Python 3: IF enter number then text code continues; if enter text or nothing than restart code: Doesn't Work -


while 1:     try:         distance=1         time = input("how long did take reach 1 mile in seconds: ")         f = float(time)         speed =((distance/time)*60)*60         print("car",registration_plate,"was going at" ,speed,"mph")         speed_limit=60         if speed > speed_limit:             print("car","'",registration_plate,"'"," speeding")         if speed ==speed_limit or speed<speed_limit:             print("car","'",registration_plate,"'"," not speeding")     except valueerror:         quit 

first here working ask.

while 1:     try:         distance=1         registration_plate="whatever want"         time = input("how long did take reach 1 mile in seconds: ")         f = float(time)         speed =((distance/f)*60)*60         print("car",registration_plate,"was going at" ,speed,"mph")         speed_limit=60         if speed > speed_limit:             print("car","'",registration_plate,"'"," speeding")         if speed ==speed_limit or speed<speed_limit:             print("car","'",registration_plate,"'"," not speeding")     except valueerror:         quit() 

you forgot declare registration_plate, next after except valueerror: quit function use quit().

note: calling quit() closes current instance of python environment. safer break or use variable while, example:

exitloop=true while exitloop:     try:          #do code here      except valueerror:         exitloop=false 

another note: try explain problem in body, not in title. makes understanding problem lot easier.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -