0

I just can't figure out whats wrong with my little game. It gives always same answer printing "That's too high, pick lower." I have no idea what I did wrong.

import random
global number
number = random.randint(1,20)


def start():
    name = raw_input("Welcome, what's your name?")
    print "Hello %s guess the number from 1 to 20!" % (name)
    game()


def game():
    print "Guess a number!"
    guess = int(raw_input(">"))


    if (guess > number):
        print "That's too high, pick lower."
        game()


    if (guess < number):
        print "That's too low, pick higher."
        game()


    if (guess == number):
        print "Yay that's the right one!"



start()
Juupperi
  • 1
  • 1
  • `int(raw_input(">"))` – Avinash Raj Apr 04 '15 at 07:37
  • Oh and the number is some random number in range from 1 to 20. – Juupperi Apr 04 '15 at 07:37
  • I don't see where you've initialised `number` in your code. Please [edit your post](http://stackoverflow.com/posts/29443936/edit) and update your code so that it provides a [minimal, **complete**, and verifiable example](http://stackoverflow.com/help/mcve). – GoBusto Apr 04 '15 at 07:40
  • 1
    brackets around conditions unnecessary. Use loop instead of recursion. Use `elif` and `else`. number should be an argument of game. – Daniel Apr 04 '15 at 07:40

1 Answers1

2

First convert string into int using int() function. Raw_input gives input as string

Sachin Gupta
  • 7,805
  • 4
  • 30
  • 45