python猜数字游戏,求帮忙找错误并改正
#Thisisaguessthenumbergame.importrandomdefaskGuess():guess=input('Takeaguess.Youhave'...
# This is a guess the number game.
import random
def askGuess():
guess = input('Take a guess. You have ' + str(6-guessesTaken) + ' tries left: ')
guess = 0
guessesTaken = 0
print('Hello! What is your name?')
myName = raw_input()
number = random.randint(1, 20)
print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')
while guessesTaken < 6:
askGuess()
if guess < number:
print('Your guess is too low.')
else :
print('Your guess is too high.')
if guess == number:
print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
elif guess != number:
print('Nope. The number I was thinking of was ' + number)
新手,看不出有几处错误,请教如何改正,急!!谢谢!!! 展开
import random
def askGuess():
guess = input('Take a guess. You have ' + str(6-guessesTaken) + ' tries left: ')
guess = 0
guessesTaken = 0
print('Hello! What is your name?')
myName = raw_input()
number = random.randint(1, 20)
print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')
while guessesTaken < 6:
askGuess()
if guess < number:
print('Your guess is too low.')
else :
print('Your guess is too high.')
if guess == number:
print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')
elif guess != number:
print('Nope. The number I was thinking of was ' + number)
新手,看不出有几处错误,请教如何改正,急!!谢谢!!! 展开
展开全部
#coding=utf-8
'''
Created on 2014-11-04
@author: Neo
'''
# This is a guess the number game.
import random
def askGuess():
guess = raw_input('Take a guess. You have ' + str(6-guessesTaken) + ' tries left: ')
guess = int(guess)
return guess
guess = 0
guessesTaken = 0
print('Hello! What is your name?')
myName = raw_input()
number = random.randint(1, 20)
print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')
while guessesTaken < 6:
guess = askGuess()
guessesTaken += 1
if guess < number:
print ('Your guess is too low.')
elif guess > number :
print ('Your guess is too high.')
else:
break
if guess == number:
print('Good job, ' + myName + '! You guessed my number in ' + str(guessesTaken) + ' guesses!')
elif guess != number:
print('Nope. The number I was thinking of was ' + str(number))
结果:
Hello! What is your name?
god
Well, god, I am thinking of a number between 1 and 20.
Take a guess. You have 6 tries left: 10
Your guess is too low.
Take a guess. You have 5 tries left: 15
Your guess is too high.
Take a guess. You have 4 tries left: 12
Your guess is too high.
Take a guess. You have 3 tries left: 11
Good job, god! You guessed my number in 4 guesses!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |