1)到目前为止,我有while循环的代码,但我只想循环12次:
print ("Please enter the 12 monthly figures")
input ("Enter a value in the range 0 to 300:")
我试过一个for循环,但没有成功
2)我想为我的代码创建一个菜单,到目前为止我有:
print ("Please choose one of the following options:")
ans=True
while ans:
print ("""
0. Quit
1. Work out and display the total
3. Work out and display the mean
4. Work out and display the standard deviation
5. Work out and display the median
6. Work out and display the lowest and second lowest
7. Work out and display the 3 month
8. Work out and display the months
9. Work out display level
""")
但我想让用户选择一个
1)可以将
range()
与for循环一起使用,例如:2)可以对多个可能的值使用一系列
if
和elif
语句,例如:它们所做的是,首先检查第一条语句是否为真,然后如果不是真,则转到下一条语句,直到没有剩下语句或者其中一条语句为真。 希望这有帮助。你知道吗
试试这个:
以及
显然Python没有switch/case循环,所以可以构建一些if语句。如果您使用的是2.7,那么您将使用原始输入作为用户输入,如果是3.x,那么您将只使用输入。你知道吗
以此类推。另外,我认为如果你把int(input)或任何你分配给你的输入,它会工作,因为input需要一个字符串,所以你必须转换它。你知道吗
相关问题 更多 >
编程相关推荐