Python Forum
while loop not working-I am using sublime text editor - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: while loop not working-I am using sublime text editor (/thread-39351.html)



while loop not working-I am using sublime text editor - mma_python - Feb-03-2023

The while loop is not working for the program below. I am using python 3.6 and practicing on sublime text editor:

prompt="\n Please enter the names of the city you have visited in Europe:"
prompt+="\n (Enter 'quit' when you are finished.)"
while True:
	city=input(prompt)
	if city=='quit':
		break
	else:
		print(f"i'd love to go to {city.title()}.")

The out-put is as below:

Please enter the names of the city you have visited in Europe:
(Enter 'quit' when you are finished.)

(I do not understand where to put the value of the city and why it does not run infinitely. It also does not show the last print command). Please see the attached screenshot.


RE: while loop not working-I am using sublime text editor - menator01 - Feb-03-2023

Please post code in bb tags to hold formatting.

Maybe something like this

print('Please enter the name of cities.\nEnter quit when finished')
while True:
    city = input('>> ')
    if city.lower() == 'quit':
        print('Goodbye!')
        break
    else:
        print(f'I\'d love to go to {city.title()}.')



RE: while loop not working-I am using sublime text editor - deanhystad - Feb-03-2023

I don't understand your question. Are you wondering how you can enter input for your program? If so, read this:

https://www.simplifiedpython.net/sublime-run-python/

Look for "Taking Input from User".


RE: while loop not working-I am using sublime text editor - mma_python - Feb-05-2023

[attachment=2241]
Thanks for your reply. It is still not working on sublime text editor I am using. To clarify further, please see the attachment which shows the program I am trying to practice. The while loop doesn't show any value.


RE: while loop not working-I am using sublime text editor - deanhystad - Feb-05-2023

I have no idea what your question is. What do you mean by "not working"? And what do you mean by not working on sublime text editor? Does it work if you run from a command line?