+ 1

Help to identify the problem in the Python code

I am Shivashankar and I tried a small python program. I created two set of programs where both are same. However for the 1st program when I type "quit" it does not break the loop runs infinite loop. But for the 2nd set the code breaks the loop - works perfect. What is the problem in 1st program? Why is it running infinite loop? I pasted two program down below. Please help me. ############## FIRST PROGRAM - does not quit & runs infinite loop while True: x=input("> ") if x.lower()=="help": print("start - To start the car") print("stop - To stop the car") print("quit - To quit the program") elif x.lower()=="start": print("car started - Ready to go!!") elif x.lower()=="stop": print("car stopped - You can disembark!") elif x.lower=="quit": break else: print("Hey! I don't understand that.") ############# SECOND PROGRAM - works well when "quit" while True: x=input("> ") if x.lower()=="help": print("start - To start the car") print("stop - To stop the car") print("quit - To quit the program") elif x.lower()=="start": print("car started - Ready to go!!") elif x.lower()=="stop": print("car stopped - You can disembark!") elif x.lower()=="quit": break else: print("Hey! I don't understand that.")

22nd Jun 2019, 12:56 AM
shivashankar sukumar
shivashankar sukumar - avatar
1 Answer
+ 2
In the first code, you dont have paranthesis() after x.lower in the “quit” else if statement: elif x.lower()==“quit”:
22nd Jun 2019, 1:07 AM
Jake
Jake - avatar