1 / 5
Feb 2022

Hello
I’m trying to create a program for learning vocabulary and I have a problem with nesting the for loop, namely in the following code I do not know how to make the external iterator not iterate each element from the inner loop, but jump to the next element. Below is an excerpt from the problematic code

pol=[‘biały’, ‘czarny’,‘zielony’]
ang=[‘white’, ‘black’,‘green’]
for i in pol:
for j in ang:
typ=input('Write a word < '+i+ ’ > in english: ')
if typ==j:
print(‘Good’)
else:
print(‘Wrong’)
break

Python, so indentation is important right?

Please edit your post and put three back ticks ``` on a line all by themselves both before and after the code. This will preserve the indentation.

11 days later

I’m trying to create a program for learning vocabulary and I have a problem with nesting the for loop, namely in the following code I do not know how to make the external iterator does not iterate every element from the inner loop, but jumps to the next element. Below is an excerpt from the problematic code

pol=[‘white’, ‘black’,‘green’]
ang=[‘white’, ‘black’,‘green’]
for i in pol:
for j in ang:
type=input('Write the word < '+i+ ’ > in English: ')
if type==j:
print(‘Excellent!’)
else:
print(‘Unfortunately wrong.’)
break

How about something like this?

pol=['bialy', 'czarny', 'zielony']
ang=['white', 'black', 'green']
for i in range(len(pol)):
    typ=input('Write a word < ' + pol[i] + ' > in english: ')
    if typ==ang[i]:
        print('Good')
    else:
        print('Wrong')

(Next time, please use three back ticks as I mentioned before to keep the code formatted.)

2 months later