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

20th Sep 2019, 6:49 AM
Venkatesh
2 Antworten
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
20th Sep 2019, 7:00 AM
Russ
Russ - avatar
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
20th Sep 2019, 9:14 AM
Cody Sharp
Cody Sharp - avatar