4E756E6F
4E756E6F

Reputation: 3

'None' in python output

I started learning python in the weekend and whenever I ask for the user input, after what's inside the print there's always a None in the output.

code:

    print('start - to start the car')
    print('stop - to stop the car')
    print('quit - to exit')
    print('help - to display this menu')
    
    contador = 1
    while contador == contador:
        user_input = input(print('> '))
        user_input.upper()
        if user_input == 'HELP':
            print('start - to start the car')
            print('stop - to stop the car')
            print('quit - to exit')
            print('help - to display this menu')
        elif user_input == 'START':
            print('Car started... Ready to go!!')
        elif user_input == 'STOP':
            print('Car stopped!')
        elif user_input == 'QUIT':
            break
        else:
            print('Command not identified!')

output:

start - to start the car
stop - to stop the car
quit - to exit
help - to display this menu
>
None

Upvotes: 0

Views: 61

Answers (2)

Yash Agrawal
Yash Agrawal

Reputation: 62

Fix the 8th line

user_input = input('> ')

You don't need to write print the input accepts the string which is to be shown while taking the input.

Upvotes: 0

Random Davis
Random Davis

Reputation: 6857

input(print('> ')) displays None because print() returns None. Just do input('> '), which will print the correct thing.

Upvotes: 3

Related Questions