到目前为止,这是我的while循环。我问用户他们完成了多少作业,只能在1到10之间(从0到5分)
但是,如果他们回答10以下的任何问题,我希望to代码自动将其输入为零,而不是用户必须为他们尚未完成的每个任务手动输入0
现在我的代码会要求用户输入10次成绩,但我只想根据用户完成多少作业的答案输入成绩。因此,如果他们回答了7个问题,那么这个问题将被呈现7次,三个0分将自动计入平均值
while True:
result = input("How many assignments did you complete? ")
if result.isdigit() and 0 <= int(result) <= 10:
break;
print ("Try a number between 1 and 10")
total = 0
gradeCount = 0
while gradeCount < 10:
grade = float(input('What was assignment score: '))
if grade < 0 or grade > 5:
print('It should be a number from 0 to 5')
else:
gradeCount += 1
total += grade
aaverage = total / 30 * 100
print('Average: ', aaverage)
数一数作业的数量。此外,你还必须除以50,因为最多分配10个作业,所以得50分
相关问题 更多 >
编程相关推荐