我用石头,纸或剪刀做游戏。我想安装一个游戏计数器,但是我不知道如何使它工作。停止在1。我想玩更多的游戏,并向柜台显示我玩过的游戏的数量。
import random
stop = False
while (not stop):
games_count = 0
you = input('Player 1: Please type your choice: rock, paper or scissors: ')
oponent = ['rock', 'paper', 'scissors']
choice = random.choice(oponent)
games_count += 1
print('the oponent choice is: ', choice)
if choice == you:
print('DRAW GAME')
elif choice == 'rock' and you == 'paper':
print('YOU LOST')
elif choice == 'rock' and you == 'scissors':
print('YOU WON')
elif choice == 'paper' and you == 'rock':
print('YOU WON')
elif choice == 'paper' and you == 'scissors':
print('YOU LOST')
elif choice == 'scissors' and you == 'rock':
print('YOU LOST')
elif choice == 'scissors' and you == 'paper':
print('YOU WON')
else:
print('Wrong answer, please type rock, paper or scissors in your next attempt!')
answer = input('Do you want to start a new game? (y for yes, any for no): ')
if answer == 'y':
print('New game will start')
print('jocuri terminate: ',games_count)
elif answer == 'no':
stop = True
print('GAME OVER')
else:
print('Wrong answer, please type Yes or No in your next attempt!')
stop = True
答案 0 :(得分:0)
您的计数器在每次迭代时都会重新初始化为0
,因为它在循环中。
while not stop:
games_count = 0
...
相反,请在循环外部对其进行初始化。
games_count = 0
while not stop:
...
作为旁注,您可能希望查看other implementations of rock-paper-scissor that do not rely on a big list of if-statement。