Omnimaga
General Discussion => Technology and Development => Computer Programming => Topic started by: jb3navides on June 11, 2013, 08:35:48 pm
-
hey guys what I need is piece of code that will do this:
if weight_p == (a letter, symbol, or anything other than a number)
then print this and restart the function
def weight_for_p():
global weight_p
print "How much does your pork weigh(kg)?"
weight_p = float(raw_input(">"))
-
def weight_for_p():
global weight_p
isnt_num=True #loop once
while isnt_num: #loop if weight_p isn't a number
print "How much does your pork weigh(kg)?"
try:
isnt_num=False #don't loop again
weight_p = float(raw_input(">"))
except ValueError: #if there is a value error, do this
isnt_num=True #loop again
print "you suck at inputting numbers" #print that you suck at inputing numbers
A few questions:
What do you need this for? I'm not going to assume anything, but I hope you aren't just copy and pasting this into an assignment.
Why do all of your questions involve meat in some way? Am I the only one here who knows python?
-
thanks for the help, I'm doing some practice exercises for an IT class, I have to make a calculator for meat times and temperatures using the data the teacher gave me, I'm gonna study this to see how it works.
-
if you already have one thread dedicated to you asking for python help (here (http://ourl.ca/19063/350667;topicseen#new)), please don't open a duplicate. that being said, i'm glad people were able to help you out =)