Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不使用if/else语句的代码_Python_If Statement - Fatal编程技术网

Python 不使用if/else语句的代码

Python 不使用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

这是我评估的开始。我能提供一些帮助吗?

您的代码有一些缩进问题,而且用户输入的总是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 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