尝试在 python 2.7 中创建决策菜单。
不能让选项是个人的,而不是按顺序排列的。
除了if给出语法错误之外的任何东西
pc = 英镑换算
kc = 千克换算
cont = 1
while cont == 1:
if input("Would you like to convert to pounds or kilograms?") == 'pounds':
pc = 1
if pc == 1:
kilograms = float(input("Enter the amount of kilograms: "))
pounds = kilograms / 2.205
print('The amount of pounds you entered is ', kilograms,
' This is ', pounds, ' pounds ')
pc = 0
if input('Do you want to go again? (y/n) ') == 'n':
cont = 0
if input("Would you like to convert to pounds or kilograms?") == "kilograms":
kc = 1
if kc == 1:
pounds = float(input("Enter the amount of pounds: "))
kilograms = pounds * 2.2
grams = kilograms * 1000
print('The amount of pounds you entered is ', pounds,
' This is ', kilograms, ' kilograms ', 'and', grams,
'grams' )
kc = 0
if input('Do you want to go again? (y/n) ') == 'n':
cont = 0
在kilograms第一次提示时输入“PC未定义”
并且程序只有在您输入poundsfirst, kilogramssecond时才能正常运行
斯蒂芬大帝
慕莱坞森
相关分类