今天我想我可能有一个简单的问题。我有一些代码要求用户选择一个从 1 到 10 的数字,它指的是一个列表。如果用户输入不正确,即 55,我将循环返回什么代码并要求他们进行另一个选择。到目前为止,我有以下代码,但我不确定如何让它循环。提前致谢
print 'Choose a Base Weather Station'
print 'Enter the corresponding station number'
selection = int(raw_input('Enter a number from: 1 to 10'))
if selection == 1:
print 'You have selected Karratha Aero as your Base Station'
elif selection == 2:
print 'You have selected Dampier Salt as your Base Station'
elif selection == 3:
print 'You have selected Karratha Station as your Base Station'
elif selection == 4:
print 'You have selected Roebourne Aero as your Base Station'
elif selection == 5:
print 'You have selected Roebourne as your Base Station'
elif selection == 6:
print 'You have selected Cossack as your Base Station'
elif selection == 7:
print 'You have selected Warambie as your Base Station'
elif selection == 8:
print 'You have selected Pyramid Station as your Base Station'
elif selection == 9:
print 'You have selected Eramurra Pool as your Base Station'
elif selection == 10:
print 'You have selected Sherlock as your Base Station'
else:
print 'You have made an error. Please chose a number from 1 to 10'