错误说user_input是未定义的,该怎么办?

时间:2016-08-25 14:04:03

标签: python

代码如下。请帮忙。

num1 = float(raw_input("Enter a number"))
num2 = float(raw_input("Enter another number"))
while True:
    print("Select one of the following options")
    print("'Add' for addition")
    print("'Subtract' for subtraction")
    print("'Multiply' for multipication")
    print("'Divide' for division")
    print("'Quit' for closing the application")
    user_input == raw_input("Enter your choice: ")

if user_input == 'Add':
    print num1 + num2
elif user_input == 'Subtract':
    if num1 < num2:
        print num2 - num1
    else:
        print num1 - num2
elif user_input == 'Multiply':
    print num1 * num2
elif user_input == 'Divide':
    print num1/num2
elif user_input == 'Quit':
    break

The image shows the code and the error

3 个答案:

答案 0 :(得分:1)

您正在使用不正确的平等分配。 ==而不是=

user_input == raw_input("Enter your choice: ") 

应该是

user_input = raw_input("Enter your choice: ")

答案 1 :(得分:1)

user_input == raw_input("Enter your choice: ")

应该是

user_input = raw_input("Enter your choice: ")

只有一个相同的字符

答案 2 :(得分:0)

更改

user_input == raw_input("Enter your choice: ")

user_input = raw_input("Enter your choice: ")