user_input() = input("Please enter a number: ") ^ SyntaxError: cannot assign to function call
user_input() = input("Please enter a number: ") ^ SyntaxError: cannot assign to function call
要求用户输入一个数字并检查输入是否为'POSITIVE'
、'ZERO'
、'NEGATIVE'
def is_positive():
# input() returns str
user_input() = input("Please enter a number: ")
# cast input into int -> int()
n = int(user_input)
# check conditions
if n > 0:
print("POSITIVE")
elif n == 0:
print("ZERO")
else:
print("NEGATIVE")
关闭只需将用户输入的变量名称更改为没有括号即可。括号用于调用函数,这就是引发错误的原因。
user_input = input("Please enter a number: ")
要求用户输入一个数字并检查输入是否为'POSITIVE'
、'ZERO'
、'NEGATIVE'
def is_positive():
# input() returns str
user_input() = input("Please enter a number: ")
# cast input into int -> int()
n = int(user_input)
# check conditions
if n > 0:
print("POSITIVE")
elif n == 0:
print("ZERO")
else:
print("NEGATIVE")
关闭只需将用户输入的变量名称更改为没有括号即可。括号用于调用函数,这就是引发错误的原因。
user_input = input("Please enter a number: ")