猜数字游戏

时间:2017-03-29 08:13:17

标签: python-2.7

我得到一些错误,不知道如何解决它们我对编码很新。 能得到一些帮助真的很棒。

#Author : John Smith
#Date   : 3/19/17
#
#Guess the number game
#1 Player vs. Computer
import random
minGuess = 1
maxGuess =6

#Ask the user for their name and their guess
name = input("What is your name")
print("Hi + name")
print("Enter a number between: " +minGuess + " and " + maxGuess)
guess = int(input("what is your guess?"))

#Generate a random number and tell the user if they have won or lost
secretNumber = random.randint(minGuess, maxGuess)
if (guess != ??????)
    print("congratz you got it right")
else:
    print("You loose the number was ???")

print("Thankyou for playing guess the number.")

2 个答案:

答案 0 :(得分:0)

如果您想使用上面一行中的变量名,

print("Hi + name")应为print("Hi "+ name)

我猜您的错误来自此行if (guess != ??????)。您需要将" ??????"(因为它对Python没有任何意义)更改为其他内容。你怎么想"猜测"应该比较?

答案 1 :(得分:0)

如果你能写出你得到的错误,那就太好了。 我能看到的唯一问题是if(guess != ??????) 表达方式 ??????未定义,在python中也无效,因为var name