#Guess the number game by Johnathan Millsap
import random
guessesTaken = 0
print('Hello! What is your name?')
myName = input()
number = random.randint(1, 100)
print('Well, ' + myName + ', I am thinking of a number between 1 and 100.')
print('Try to guess it!.')
while guessesTaken <= 3:
print('Take a guess.')
guesesTaken = guessesTaken + 1
guess = input()
guess = int(guess)
if guess < number:
print('Your guess is too low.')
if guess > number:
print('Your guess is too high.')
if guess == number:
if guess == number:
guesesTaken = str(guessesTaken)
print('Good job, ' + myName + '! You guessed my number ' + guessesTaken + ' guesses!')
if guess != number:
number = str(number)
print('Nope. The number I was thinking of was ' + number)
我遇到的主要问题是它一直告诉我我的 int 不会隐式转换为字符串......我也试图在 1-100 和 1-1000 和 1-10000 等三个不同的困难中做到这一点。对此的任何帮助将不胜感激。
Traceback (most recent call last):
File "Lab4.py", line 28, in <module>
print('Good job, ' + myName + '! You guessed my number ' + guessesTaken + ' guesses!')
TypeError: Can't convert 'int' object to str implicitly
Terminated with exit code 1.