使用 if 语句减少'player'计数



>我正在尝试为用户必须猜测计算机生成的值的游戏编写脚本。目标是减少玩家数量,直到其值为 1,此时结束。

import random 
import time
players = input("Let's play Five's! How many are you?:" )
#print("you are", players, "players?") #test number of players
players = int(players)

if players <=1:
print("Game Over")
else:
while players >= 1:
players = players+1
#Decide possible values than can be chosen
options = [] #Possible options
for i in range(0,players):
x = i * 5
options.append(x)
print("Your choices are", options)
#Playing the game
#Each turn
guess = random.choice(options)
print("Computer has chosen", int(guess))
count_down = 3
while (count_down):
print(count_down)
time.sleep(1)
count_down -=  1
choice = input("Guess:")
choice = int(choice)
if choice not in options: #If choice isn't a multiple of 5
input("Not allowed, choose again:")
elif choice in options and choice != guess: #Valid choice but wrong
print("Wrong")                      #so player is still in the
else:                                       #game
choice = int(choice)
if choice == guess: #Correct choice so player leaves game
print("You're Out.") # this should reduce the player count
players -=1

我已经包含了打印计算机生成值的行,所以我可以给出正确的猜测,但即使猜对了,它也不会减少玩家数量,因此游戏无限继续

while循环的第一行添加一个播放器。

players = players+1

然后你减去最后一行的玩家

players -=1

如果我正确理解您的代码,玩家数量不会改变。

最新更新