while inside while loop | Sololearn: Learn to code for FREE!

0

while inside while loop

i want to continue the loop if user type 'y' .. pls see this and run this code.. tell me where im wrong?? class ReverseString(): def __init__(self,word): self.word=word def reverseit(self): print((self.word)[::-1]) while True: userinput= input('Enter a word or sentence :' ) result=ReverseString(userinput) result.reverseit() while True: askuser=input('do u want to continue: y/n') if askuser== 'y' or 'Y': continue elif askuser== 'n' or 'N' : break else: print('Enter only y or n') continue

9/20/2019 6:49:03 AM

Venkatesh

2 Answers

New Answer

0

Your code isn't showing. Maybe you can do this: while True: # Your code block if input('Do you want to continue?') != "y": break

0

You have a nested while loop, so if you write break in it, it will break the outside loop. That can be fixed in this way: while True: userinput = input("Enter a word: ") print("\n") result = ReverseString(userinput) result.reverseit(result) while True: an = input("Continue? (y/n): ") if an.lower == "y": break elif an.lower == "n": continue else: print("Enter y or n") And note that you can’t call input more than two times in SoloLearn console