To compare n and N simultaneously in a Python conditional statement

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

import random

while True:
    name=input('What is your name?:')
    print(name 'sir', 'hello?')

    dice=random.randint(1,6)
    if dice==1:
        print ('.'.')
    elif dice==2:
        print('n.')
    elif dice==3:
        print('.'.')
    elif dice==4:
        print('h.')
    elif dice==5:
        print ('a')
    else:
        print('b.')
    print ('Thank you.')

    input('Do you want to stop the system?')

    if answer=='Y'or'y':
        break
    elif answer=='N'or'n':
        continue

I want to return to the beginning only when I enter 'N' or 'n' at the end of this code, but what should I enter other than continue?

python

2022-09-20 08:56

1 Answers

"""
if answer=='Y'or'y':
    break
elif answer=='N'or'n':
    continue
"""

# 1
if answernot in ['N', 'n']:
    break
# 2
if answer != 'N' and answer != 'n':
    break
# 3
if answer.upper() != 'N':
    break
# 4
if answer.lower() != 'n':
    break


2022-09-20 08:56

If you have any answers or tips


© 2022 pinfo. All rights reserved.