I'm new to coding and learning python... I was trying to check if an input is a number or not. I found a great answer from an inactive account 3 years ago that looks like this:
a=(raw_input("Amount:"))
try:
int(a)
except ValueError:
try:
float(a)
except ValueError:
print "This is not a number"
a=0
if a==0:
a=0
else:
print a
#Do stuff
https://stackoverflow.com/a/26451234/8032074
My question is, what exactly is happening from if a==0
until the end? I can tell that if I take it out, ALL input will end up getting printed, even if it's not a number.
But how exactly is that code preventing non-numerical entries from getting printed?
Thanks!!