下面是我的代码,我要创建一个列表,其中包含应该有距离的地方。用户应该选择两个不同的地方来查看它们之间的距离(以英里为单位),然后可以选择转换为公里。不过,我完成了代码,所以它工作了,然后我去添加一个if语句,应该说“如果用户输入place1,place2或place3,然后继续要求用户输入第二个位置,否则重新启动程序回到开始。但是if语句写得不正确,现在它说“Second未定义”
print 'The available places to select from are:'
print 'place1, place2, place3: '
place1 = 50
place2 = 40
place3 = 30
Convert = 1.609344
First = str(raw_input('Please select from the list where you are coming from'))
if raw_input == 'place1' 'place2' 'place3':
Second = str(raw_input('Please select where you are going to: '))
else:
print 'please press any key to restart'
Distance = First + Second
print "the distance between the two places are", Distance, "miles"
Kilometres = bool(input('Would you like to convert to Kilometres? please type True to convert or False to exit: '))
if True:
print 'The distance in Kilometres is',First + Second / Convert, 'Kilometres'
else:
print 'press any ket to terminate'
不要缩进你的if语句。你知道吗
而不是
编辑:
看来你需要一些帮助。我重新编写了你的代码,并添加了一些注释,希望能把事情弄清楚。你知道吗
相关问题 更多 >
编程相关推荐