Python 不使用if/else语句的代码
这是我评估的开始。我能提供一些帮助吗?您的代码有一些缩进问题,而且用户输入的总是str string类型。在检查if语句之前,需要将权重转换为int。您还应该使用num1>15而不使用=,因为您已经在num1中使用了它。我删除了标记类,因为您的代码与itelif无关。num1>15应该是elsePython 不使用if/else语句的代码,python,if-statement,Python,If Statement,这是我评估的开始。我能提供一些帮助吗?您的代码有一些缩进问题,而且用户输入的总是str string类型。在检查if语句之前,需要将权重转换为int。您还应该使用num1>15而不使用=,因为您已经在num1中使用了它。我删除了标记类,因为您的代码与itelif无关。num1>15应该是else print("Select operation.") print("1.Price of your luggage") print("2.Exit") # Take input from the u
print("Select operation.")
print("1.Price of your luggage")
print("2.Exit")
# Take input from the user
choice = input("Enter choice(1/2:")
if choice == '1':
num1=(input("Enter wieght of your first luggage " ))
if num1 <=15:
print('Your first item is free')
elif num1 >=15:
print('Your items will cost you money')
elif choice == '2':
raise SystemExit()
print("Select operation.")
print("1.Price of your luggage")
print("2.Exit")
# Take input from the user
choice = input("Enter choice(1/2:")
if choice == '1':
num1 = int(input("Enter wieght of your first luggage " ))
if num1 <= 15:
print('Your first item is free')
else:
print('Your items will cost you money')
elif choice == '2':
raise SystemExit()
Select operation.
1.Price of your luggage
2.Exit
Enter choice(1/2:1
Enter wieght of your first luggage 12
Your first item is free