def main ():
input('press enter to begin testing...')
counter = 0
total = 0;
value = int( input ("Enter temp: or q to quit " ))
maxval = value
minval = value
while value:
counter += 1
total += value
if value > maxval:
maxval = value
if value < minval:
minval = value
value = int( input ("Enter temp: or q to quit "))
print ( 'Total is: ', total)
print ('Counter is: ', counter)
if counter != 0:
print ('Average is: ', total / counter)
print ('Minimum is: ', minval)
print ('Maximum is: ', maxval)
问题在于要求temp
或q
退出,因为它是一个int q
,因为它是str。
我尝试了单独的问题但是它没有正确计算循环。然后我尝试了ord ('q')
113
。我不确定如何成功应用或有更好的方法。
答案 0 :(得分:1)
您应该首先检查其内容:
,而不是将值直接转换为int
value = input ("Enter temp: or q to quit ")
if value == 'q':
return
value = int(value)