代码无法与if / else语句一起使用

时间:2018-10-20 11:42:29

标签: python if-statement

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()

这是我评估的开始。我可以帮忙吗?

1 个答案:

答案 0 :(得分:2)

您的代码存在一些缩进问题,并且用户输入始终为jQuery(document).ready(function () { jQuery('#restore_plugin_backup').click(function () { var form_data_restore = new FormData(); form_data_restore.append('backup_file', jQuery("#backup_restore_file")[0].files[0]); jQuery.ajax({ type: 'POST', url: ajaxurl, data: form_data_restore, contentType:false, // this dataType: false, cache:false, success: function (response) { alert(response); } }); }); }); 类型(字符串)。在检查if语句之前,需要将权重转换为str。您还应该使用int,而不使用num1 > 15,因为您已经在=中使用过它。这是更正的代码。正如评论中khelwood所指出的那样,您的num1 <= 15可以简单地用elif代替,因为如果数字不小于15,它将大于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 = 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()