Home > Software design >  user_input() = input("Please enter a number: ") ^ SyntaxError: cannot assign to function c
user_input() = input("Please enter a number: ") ^ SyntaxError: cannot assign to function c

Time:01-17

ask the user to enter a number

and check if the input is '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")

CodePudding user response:

Close just change the user input variable name to have no parentheses like so. The parentheses are meant for when you are calling a function which is why an error was raised.

user_input = input("Please enter a number: ")
  •  Tags:  
  • Related