我无法弄清楚我的小游戏有什么问题。它总是提供相同的答案打印"它太高,选择较低。"我不知道我做错了什么。
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()
答案 0 :(得分:2)
首先使用int()函数将字符串转换为int。 Raw_input将输入作为字符串