Monday, 15 June 2015

How do I break a loop inside of a loop in python? -



How do I break a loop inside of a loop in python? -

this code loop reviews vocabulary words. reason, break isn't working.

here words programme uses:

vocab ={'adherent' : "a person follows or upholds leader, cause, etc.; supporter; follower.", 'incoherent' : "without logical or meaningful connection; disjointed; rambling", 'inherent' : "existing in or permanent , inseparable element, quality, or attribute" , 'diffuseadj' : "characterized great length or discursiveness in speech or writing; wordy"}

here loop:

while 1: ques1= raw_input("would list of vocabulary words, or play game? type 'words' or 'game': ") if ques1 == 'words': ques11= raw_input("type 'w' words only, type 'wd' words , definitions, type 'd' definitions only: ") if ques11 == "w": key,value in vocab.iteritems(): print key elif ques11 == "wd": key,value in vocab.iteritems(): print key,"-", value elif ques11 == "d": key,value in vocab.iteritems(): print value elif ques1 == 'game': game=raw_input("type 'rw' random words: ") if game == 'rw': while 1: y = random.choice(vocab.keys()) print y t2=raw_input("what definition?: ") if t2 in vocab[y]: print 'all words in definition!' print vocab[y] elif t2 not in vocab[y]: print vocab[y] elif t2 == 'menu': break raw_input("hit 'enter': ") else: raw_input("hit 'enter': ")

for reason break game loop doesn't homecoming 'ques1'. why won't break work?

the problem code break statement never reached if t2 not in vocab. can alter

elif t2 == 'menu': break

to

if t2 == 'menu': break

python

No comments:

Post a Comment