Author Topic: Coding help  (Read 2816 times)

0 Members and 1 Guest are viewing this topic.

Offline jb3navides

  • LV1 Newcomer (Next: 20)
  • *
  • Posts: 8
  • Rating: +0/-0
    • View Profile
Coding help
« 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()
« Last Edit: June 11, 2013, 05:06:38 am by jb3navides »

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: Coding help
« Reply #1 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
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline ElementCoder

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 611
  • Rating: +42/-2
    • View Profile
Re: Coding help
« Reply #2 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' :)
« Last Edit: June 12, 2013, 02:36:05 am by ElementCoder »

Some people need a high five in the face... with a chair.
~EC