Ask coding questions

← Back to all posts
1
Question
GabrielZandie (0)

what code is it for yes or no question like if you are on a website and you see do you want to log in or sign up I would like the code for it.

Commentshotnewtop
1
JustARatherRidi (185)

Here's how you can check whether the user wants to log in or not, and make the program continue accordingly:

response = input("Would you like to login? ").lower()

if response in ('y', 'yes'):
    username = input('Please enter your username: ')
    print(f'\nWelcome, {username}!')

elif response in ('n', 'no'):
    print('Okay, bye!')

else:
    print('Invalid input, try again!')

(Working repl)


If you were looking for something else, please try to make your question a bit more specific.