Author Topic: please help  (Read 2673 times)

0 Members and 1 Guest are viewing this topic.

Offline jb3navides

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 8
  • Rating: +0/-0
    • View Profile
please help
« 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
Code: [Select]
def weight_for_p():
    global weight_p
    print "How much does your pork weigh(kg)?"

    weight_p = float(raw_input(">"))

Offline Hooloovoo

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 225
  • Rating: +22/-0
    • View Profile
Re: please help
« Reply #1 on: June 11, 2013, 09:29:49 pm »
Code: [Select]
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?
"My world is Black & White. But if I blink fast enough, I see it in Grayscale." -tr1p1ea
Spoiler For some of the calcs I own:



(actually I have quite a few more than this, but I don't feel like making bars for them all.)

Offline jb3navides

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 8
  • Rating: +0/-0
    • View Profile
Re: please help
« Reply #2 on: June 11, 2013, 10:49:08 pm »
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.

Offline shmibs

  • しらす丼
  • Administrator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2132
  • Rating: +281/-3
  • try to be ok, ok?
    • View Profile
    • shmibbles.me
Re: please help
« Reply #3 on: June 12, 2013, 11:37:17 am »
if you already have one thread dedicated to you asking for python help (here), please don't open a duplicate. that being said, i'm glad people were able to help you out =)