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
The code is set like this, and I want to break only when answer presses 'Y' or 'y', but the error written in the title keeps repeating. Which part should I modify?
python
The break or continue command must exist in the loop.
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
© 2024 OneMinuteCode. All rights reserved.