0

I am in middle school and just learning programming. I wrote this code in python for a guessing game but not sure what i am doing wrong. It never goes to the if statement. Can you please guide me what am I doing wrong? Thank you

import random
easy = random.randint(1,100)
medium = random.randint(1,1000)
hard = random.randint(1,10000)
guesses = 0

print "Hello, what's your name?"
name = raw_input('')

print "Hi "+ name +", welcome to the guessing game!"

ques = raw_input("Would you like the difficulty to be easy(1), medium(2) or      hard(3)?")

if ques ==1:
    num = easy
    print "I am thinking of a number from the range of 1 to a 100!"
    print "Try to guess my number."

elif ques == 2:
    num = medium
    print "I am thinking of a number from the range of 1 to a 1,000!"
    print "Try to guess my number"

elif ques == 3:
    num = hard
    print "I am thinking of a number from the range of 1 to 10,000"
    print "Try to guess my number"

while guesses < 100: 
    print "Take a guess: "
    guess = raw_input("")

    guesses = guesses + 1

    if guess < num: 
        print "Your guess is too low"

    if guess > num:
        print "Your guess is too high"

    if guess == num:
        break


if guess == num:
    guesses = str(guesses)
    print "Good job "+ name +", it took you " + guesses +"to find my   number!!!"

if guess != num:
    num = str(num)
    print('Nope, The number I was thinking of was ' + number + "!")     
Levon
  • 138,105
  • 33
  • 200
  • 191
Aayu
  • 11
  • 5
  • 1
    probably you need to do `ques = int(raw_input('....'))`, because `raw_input` must return a string –  Aug 12 '16 at 23:34
  • 2
    Just to let you know, Stack Overflow has rules that say you must be **at least 13 years or older** to use the site. So your account may get suspend. – Christian Dean Aug 12 '16 at 23:38
  • 4
    Also, as another note: If you're just learning Python, we (the Stack Overflow Python community) ***strongly*** recommend starting out with Python 3. Python 2 is the past, Py3 is the present and future. Official support for Py2 will end rather soon, in 2020, while Py3 will be supported for the foreseeable future. Many/most open-source projects are transitioning to, if they haven't already switched completely, to Python 3. More importantly, you'll learn some bad habits in Py2 that you'll have to unlearn later on when you pick up 3. Learn 3 now, and play around with 2 when you're comfortable. – MattDMo Aug 12 '16 at 23:44
  • Thank you for your suggestion, but now it is saying invalid syntax in the code: `if ques == 1:` – Aayu Aug 12 '16 at 23:51
  • @Aayu Are you sure you closed all the parentheses here: `ques = int(raw_input('....'))` – juanpa.arrivillaga Aug 13 '16 at 01:26
  • Thanks guys, turns out your suggestions were right. the new edited code is to long to show but thanks very much. – Aayu Aug 13 '16 at 04:16

0 Answers0