我正在使用 python3 并且我有这个代码,我要求用户提供三个输入。然后我对它们进行计算。我想继续将计算结果添加到列表中。怎么做?
...
if choice == '1': #my fist input x
while True:
x = int(input('Please insert the number of things you consider yourself a fan of'))
if x > 0:
break
else:
print('Please insert a number higher than 0')
elif choice == '2': #my second input y
while True:
y = int(input('Please insert the number of hobbies you like to do every month'))
if y % 4 == 0:
break
else:
print('Please insert a valid number')
elif choice == '3': #my third input z
while True:
z = int(input('Please insert the number of sports you like'))
if z > 0:
break
else:
print('Please insert a number higher than 0')
elif choice == '4': #the calculation part
import math
def square_root():
c=(42 * y ** 2)/(z + 1)
nerd_score=int(x*math.sqrt(c))
return nerd_score
print('your nerd score is', square_root())
我希望循环继续进行,并将每个结果添加到列表中。直到用户退出循环。
慕容森
相关分类