> and < mixed up in my code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Boyyini
    New Member
    • Apr 2010
    • 5

    > and < mixed up in my code?

    Hello again.
    Im making a text-based dungeon-adventure game. And I came across a strange "error" in my code.

    ">" Means "The stuff on this side is bigger > The stuff on this side is smaller"
    Right? Well when this part of my code is run, if the age the user inputs is over 21, it says "You're kinda young.. blah blah"
    But if the number they input is UNDER 21, it says "You're old enough to drink!... blah blah"

    So it seems like the greater than and less than are mixed up. Or is there something I don't understand?

    Code:
    age = raw_input("How old are you? ")
    if age < 21:
        print("You're kinda young to be playing this game... Oh well.")
    if age >= 21:
        print("You're old enough to drink! I think you can play a text-based game. He he.")
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    raw_input() returns a string, but you are comparing the string to an int. Instead of two if statements, use an if/elif block.
    Code:
    age = raw_input("How old are you? ")
    if int(age) < 21:
        print("You're kinda young to be playing this game... Oh well.")
    elif int(age) >= 21:
        print("You're old enough to drink! I think you can play a text-based game. He he.")

    Comment

    • Boyyini
      New Member
      • Apr 2010
      • 5

      #3
      Ohh, Alright. Thanks

      Comment

      Working...