Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping problem
#1
I'm trying to make a little game for my wife start off small and work my way up. but i cant loop the question if she gets it wrong.

I would like it to say try again and the question comes up but instead it says try again and press any key to exit.

i had two codes that do the same.
my code 2 codes

my first code.

name = input ('What is your name?')
print("hello " + name)
spanishs = input('Can you say my name is in Spanish?')

for spanish in spanishs:
	if spanish == 'me llamo':
		print('Si. Correcto')
else:
	print('Intento equivocado otra vez. ' 'Wrong, try again!')
my second code.

name = input ('What is your name?')
print("hello " + name)
spanishs = input('Can you say my name is in Spanish?')

for spanish in spanishs:
	if spanish == 'me llamo':
		print('Si. Correcto')
else:
	print('Intento equivocado otra vez. ' 'Wrong, try again!')
	print('Can you say my name is in Spanish?')
	spanishs = input()
just need to loop it. been at it for ages trying different ways from the internet. if i get a loop to work and then add my questions and answers it either breaks or does the same.
Reply
#2
the indentation is not correct

name = input ('What is your name?')
print("hello " + name)
spanishs = input('Can you say my name is in Spanish?')
 
for spanish in spanishs:
    if spanish == 'me llamo':
        print('Si. Correcto')
    else:
        print('Intento equivocado otra vez. ' 'Wrong, try again!')
Reply
#3
If you want to ask the question over and over again until you get a correct answer, use a while loop:

while True:
    spanishs = input('Can you say my name is in Spanish?')
    if spanish == 'me llamo':
        print('Si. Correcto')
        break
    print('Intento equivocado otra vez. ' 'Wrong, try again!')
Always put everything you want to repeat in the loop.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
(Sep-03-2018, 12:45 PM)ichabod801 Wrote: If you want to ask the question over and over again until you get a correct answer, use a while loop:

while True:
    spanishs = input('Can you say my name is in Spanish?')
    if spanish == 'me llamo':
        print('Si. Correcto')
        break
    print('Intento equivocado otra vez. ' 'Wrong, try again!')
Always put everything you want to repeat in the loop.

thanks got it to work. was going crazy trying to sort this.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020