while 1:
try:
danish_exchange = float(raw_input("Danish Krones: ")) # Reads the user input for Danish Krones
if danish_exchange <= 0:
raise ValueError
break
except ValueError:
print("Invalid entry. Please enter a number > 0.")
17 Replies - 1057 Views - Last Post: 27 February 2013 - 06:59 PM
#16
Re: problem with for loop
Posted 27 February 2013 - 06:07 PM
I tried that code that you wrote but it keeps giving me an error where it says break.
#17
Re: problem with for loop
Posted 27 February 2013 - 06:51 PM
Indentation is critical in python.
This:
Is not the same as this:
Also proper indentation should really be 4-spaces. More than 4 is fine if you feel the need, but any less starts getting hard to read. Above all, be consistent.
-Mek
This:
while 1:
try:
danish_exchange = float(raw_input("Danish Krones: ")) # Reads the user input for Danish Krones
if danish_exchange <= 0:
raise ValueError
break
except ValueError:
print("Invalid entry. Please enter a number > 0.")
Is not the same as this:
while 1:
try:
danish_exchange = float(raw_input("Danish Krones: "))
if danish_exchange <= 0:
raise ValueError
break
except ValueError:
print("Invalid entry. Please enter a number > 0.")
Also proper indentation should really be 4-spaces. More than 4 is fine if you feel the need, but any less starts getting hard to read. Above all, be consistent.
-Mek
#18
Re: problem with for loop
Posted 27 February 2013 - 06:59 PM
Thanks, I was trying to use tab but it wasn't working so I tried the space bar and it indented, weird.
|
|

New Topic/Question
Reply




MultiQuote



|