我是Python新手,正試圖讓程序從一個定義的模塊移動到下一個模塊。第一個模塊工作得很好,但不會移動到def calcAverage模塊。我附上了代碼和結果。我只在第一個模塊中設置了總和,以驗證它是否正確計算。此信息將被退回並打印到表格中。 (對不起,如果我不使用正確的術語。)我對此很新。Python 3新手 - 無法獲取程序移動到下一個模塊
下面是結果: 輸入第一個測試score.89 輸入第二個測試score.94 輸入第三測試score.100 輸入第四測試score.88 輸入第五測試score.96 在這之後467
> 什麼也沒有發生。
下面是代碼:
`#這一方案將計算出的五個測試成績的平均值。
# Print my name
print('Beth Salvatore')
# Assign corresponding letter grade.
A_score = 90
B_score = 80
C_score = 70
D_score = 60
def main():
# Get five test scores. Get first score.
test1 = int(input('Enter the first test score.'))
# Get second score.
test2 = int(input('Enter the second test score.'))
# Get third score.
test3 = int(input('Enter the third test score.'))
# Get fourth score.
test4 = int(input('Enter the fourth test score.'))
# Get fifth score.
test5 = int(input('Enter the fifth test score.'))
# Add all scores.
x = [test1, test2, test3, test4, test5]
total = sum(x)
print (total)
# Return the total of all tests.
return total
def calcAverage(score1, score2, score3, score4, score5):
# Find the average of all tests.
calcAverage = (total) /5.0
return calcAverage
print('The average test score is %', calcAverage)
def determineGrade(score):
# Assign a letter grade to the average.
if score >= A_score:
print('A')
else:
if score >= B_score:
print('B')
else:
if score >= C_score:
print ('C')
else:
if score >= D_score:
print('D')
else:
print('F')
# Return the letter grade
return score
#Print the tests and corresponding grades in a table.
print('score \t\t numeric grade \t letter grade')
print('---------------------') \
print('score 1:' test1, score)
print('score 2:' test2, score)
print('score 3:' test3, score)
print('score 4:' test4, score)
print('score 5:' test1, score)
# Call the main function.
main()`
您從來沒有調用過其他函數。 – MooingRawr
你必須調用'calcAverage()',就像你調用'main()'一樣。函數不會自動執行(使用Python或任何其他語言)。 – user3030010
您可以通過https://gist.github.com/brunsgaard/4a356691702f7aa31484031ede15a840 – brunsgaard