如何正确运行此python代码?

时间:2016-08-12 23:31:46

标签: python python-2.7

我上中学,只是学习编程。我在python中为拼写游戏编写了这段代码,但不确定我做错了什么。它从未进入if语句。你能指导我,我做错了什么吗?谢谢

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 + "!")     

0 个答案:

没有答案
相关问题