有些原因不会编译

时间:2015-02-01 20:13:20

标签: python

你好,这是我尝试制作的第一个程序,有人请帮助我,因为我无法编译。它总是在第2行说无效字符。请帮助。

编辑:Here is a link to my code

print (” 1. Convert inches to centimeters.”)
print (“2. Convert feet to meters.”)
print (“3. Convert miles to kilometers.”)
print

menu_selection = input('Enter your selection: ')

while menu_selection < 1 or menu_selection > 3:
print (“That is an invalid selection.”)
menu_selection = input('Enter 1, 2, or 3: ')

if menu_selection == 1:

inches = input('Enter the number of inches: ')
centimeters = inches * 2.54
print (“That is equal to', centimeters, 'centimeters.”)
elif menu_selection == 2:
feet = input('Enter the number of feet: ')
meters = feet * 0.3048
print (“That is equal to', meters, 'meters.”)
elif menu_selection == 3:
miles = input('Enter the number of miles: ')
kilometers = miles * 1.609
 (“That is equal to', kilometers, 'kilometers.”​)

1 个答案:

答案 0 :(得分:0)

缩进是关闭的,并且您使用错误的字符来分隔字符串,它必须是正常的双引号。换句话说,改变这个:

print (” 1. Convert inches to centimeters.”)

进入这个:

print (" 1. Convert inches to centimetres.")

当您从数字图书或未使用正确排版的类似电子内容中复制粘贴代码时会发生此类错误,而在Python中,您必须绝对尊重原始来源中的缩进 - 空白在Python程序中很重要。