Omnimaga

General Discussion => Technology and Development => Computer Programming => Topic started by: jb3navides on June 10, 2013, 11:48:35 pm

Title: Coding help
Post 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.

Code: [Select]
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()
Title: Re: Coding help
Post by: ruler501 on June 11, 2013, 12:31:42 am
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
Title: Re: Coding help
Post by: ElementCoder on June 12, 2013, 02:35:54 am
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' :)