import time
import random
# USER CHOOSES TO PLAY
play = input("Type 'Play' to play")
while play == "play":
# COMPUTER GENERATES NUMBER
number = random.randint(1,11)
# USER GOES TO GUESS THE NUMBER
print ("guess the number, the computer has picked a number between 1 and 10. You have 5 tries")
num_guess = int(input())
# CODE TELLS USER IF THEY CHOOSES THE RIGHT OR WRONG NUMBERPL
if num_guess == number:
print(f"Yes the number is {number}, good job!")
elif num_guess != number:
for numguesses in range (4, 0, -1):
num_guess = int(input(f"guess the number you have {numguesses} tries"))
play = input("Type 'Play' to play")
我不知道是否当计算机生成一个数字与'random.randint'如果它是生成一个新的数字,每次我猜它生成了什么数字(因为这是一个数字生成游戏)。请你能帮助,让我知道。
我试图使它只生成1个数字,从1,11,我有5个猜测猜测正确的数字,然后它重复,如果用户类型'播放'
1条答案
按热度按时间vuv7lop31#
第一条评论正确地回答了这个问题。
random.randint(1,11)
时,代码生成新的随机数。每次都会把新号码打印到控制台。