내 코드 역 추적의 오류 (마지막으로 가장 최근 통화)를 얻기를 찾는 데 도움이 필요() 파일 "C :/Users/Daniel Nase/Desktop/assignment 7 test.py", 줄 23, 주 calculate_weighted_average (score_ammount, scores_t, score_weight, average1, num_t) 파일 "C :/Users/Daniel Nase/float ((score_weight.pop (0))/100) TypeError : 지원되지 않는 피연산자 유형 (/)은/test/: 'str'및 'int'는 가중 평균
나는 가중 평균을 계산하려고하는데, 내가 뭘 잘못하고 있는지 모르겠다. 도와주세요 !!!!
그것은 당신이 문자열과 int를 곱 위해 노력하고 있다고하지만, 당신이 그들을 분할하려는 것이 아니다def main():
score_type = ["tests","assignments","quizzes","labs"]
score_ammount = [0,0,0,0]
score_weight = [0,0,0,0]
final_weight = 0
scores_t = [0]
scores_a = [0]
scores_q = [0]
total = 0
average1 = [0]
average2 = [0]
average3 = [0]
num_t = 0
get_initial_input(score_type,score_ammount,score_weight)
get_scores(score_ammount,average1,average2,average3,total,scores_t,scores_a,scores_q)
calculate_weighted_average(score_ammount,scores_t, score_weight, average1, num_t)
def get_initial_input(score_type,score_ammount,score_weight):
for x in range(0,4):
score_ammount[x] = input("How many " + score_type[x] + " are there?")
if input("Is there a final with a serperate weight?(1 = yes/0 = no) ") == '1':
final_weight = int(input("What is the weight of the final?(0-100) "))
else:
final_weight = ""
total_weight = 0
while total_weight != 100:
total_weight = 0
print("")
print("Please make sure the weight of all scores add up to 100")
for x in range(0,3):
score_weight[x] = input("What is the weight of all the " + score_type[x])
total_weight = total_weight + int(score_weight[x])
return score_ammount, score_weight, final_weight
def get_scores(score_ammount,average1,average2,average3,total,scores_t,scores_a,scores_q):
num_t = int(score_ammount.pop(0))
print("")
for i in range(0,num_t):
scores_t.append(0)
for i in range(0, num_t):
y = i + 1
scores_t[i] = int(input("Please input test score #" + str(y) + " "))
print(" ")
for i in range(0,1):
total = total + sum(scores_t)
average1 = total/num_t
print(int(average1))
###########################################################################
num_a = int(score_ammount.pop(0))
print("")
for i in range(0,num_a):
scores_a.append(0)
for i in range(0, num_a):
y = i + 1
scores_a[i] = int(input("Please input assignment score #" + str(y) + " "))
print(" ")
total = 0
for i in range(0,1):
total = total + sum(scores_a)
average2 = total/num_a
print(int(average2))
###########################################################################
num_q = int(score_ammount.pop(0))
print(" ")
for i in range(0,num_q):
scores_q.append(0)
for i in range(0, num_q):
y = i + 1
scores_q[i] = int(input("Please input quiz score #" + str(y) + " "))
print(" ")
total = 0
for i in range(0,1):
total = total + sum(scores_q)
average3 = 0 + total/num_q
print(int(average3))
return average1, average2, average3, total, scores_t, scores_a, scores_q, num_t, num_a, num_q
def calculate_weighted_average(score_ammount, scores_t, score_weight, average1, num_t):
num_t = int(score_ammount.pop(0))
for i in range (0,num_t):
average1[i] = sum(scores_t)/num_t
weighted_average_t = float(sum(average1))*float((score_weight.pop(0))/100)
print(weighted_average_t)
main()
오류 메시지'TypeError :/: 'str'과 'int'에 대해 지원되지 않는 피연산자 유형이 무엇을 의미한다고 생각하십니까? 네가하는 것을 당신에게 말하는 것은 무엇이라고 생각하니? – DSM
나는 str과 int를 곱하려고 노력하고 있지만 ammount1을 가지고 int가 가중 평균을 구하는 데 사용할 수있는 것이 무엇인지 알지 못한다. – user3015563