Omnimaga
General Discussion => Technology and Development => Computer Programming => Topic started by: jb3navides on June 10, 2013, 11:48:35 pm
-
Hey guys can you fix python code, when I run it and type letters (numbers only) it is supposed to restart the function, but it prints a whole load of stuff and exits the program.
def weight_for_blv():
global weight_blv
print "How much does your meat weigh(kg)?"
weight_blv = int(raw_input(">"))
if (weight_blv > 0) and (weight_blv <= 10):
doness()
elif (weight_blv <= 0) and (weight_blv > 10):
print "Invalid, type again, the minimum is greater than 0 and the maximum is 10, and numbers only"
weight_for_blv()
else:
print "Invalid, type again, the minimum is greater than 0 and the maximum is 10, and numbers only"
weight_for_blv()
-
you should use [code][/code] tags to show the code better
it is casting it to a int to start so it may well be covering up any letters typed
-
ruler pretty much said it, you're casting your input to an int so if you give it letters it errors (if those letters aren't a variable). You also may want to change the 'and' in your elif statement to an 'or' :)