I am currently trying to learn Python and working on Rock Paper Scissors game. Its a simple one and and consists of 3 rounds. Most of the things are working fine but the only problem im having right now is I cant add another round if a round is tie.
from random import randint
options = ['rock', 'paper', 'scissors']
players = 0
computers = 0
computer = options[randint(0,2)]
#introduction
print("Welcome to rock paper scissors")
print("The game is fairly simple.\n- Rock beats Scissors\n- Scissors beats Paper \n- Paper beats Rock")
start = input("To start the game type 'Start' or 's' ")
if start != 's':
print("Ok")
playerplay = False
else:
rounds = 3
playerplay = True
for loop in range(rounds):
player = input("Rock, Paper, Scissors? ").lower()
if player == computer:
print("It's a Tie!")
rounds += 1
elif player == options[0]:
if computer == options[1]:
print(computer, "covers", player)
print("Player lost, 1 point for the computer")
computers += 1
else:
print(player, 'smashes', computer)
print("Player wins, 1 point for the player")
players += 1
elif player == options[1]:
if computer == options[2]:
print(computer, "cuts", player)
print("Player lost, 1 point for the computer")
computers += 1
else:
print(player, 'covers', computer)
print("Player wins, 1 point for the player")
players += 1
elif player == options[2]:
if computer == options[1]:
print(computer, "smashes", player)
print("Player lost, 1 point for the computer")
computers += 1
else:
print(player, "cuts", computer)
print("Player wins, 1 point for the player")
players += 1
if playerplay:
print((f'Player {players}\nComputer {computers}') )
I would recommend using while
To rounds: add +1 if it's a tie and decrease -1 after every rounds and make the game run until rounds is +ive
from random import randint
options = ['rock', 'paper', 'scissors']
players = 0
computers = 0
computer = options[randint(0,2)]
#introduction
print("Welcome to rock paper scissors")
print("The game is fairly simple.\n- Rock beats Scissors\n- Scissors beats Paper \n- Paper beats Rock")
start = input("To start the game type 'Start' or 's' ")
if start != 's':
print("Ok")
playerplay = False
else:
rounds = 3
playerplay = True
# for loop in range(rounds):
while rounds: #use while loop
player = input("Rock, Paper, Scissors? ").lower()
if player == computer:
print("It's a Tie!")
rounds += 1# increase rounds left
elif player == options[0]:
if computer == options[1]:
print(computer, "covers", player)
print("Player lost, 1 point for the computer")
computers += 1
else:
print(player, 'smashes', computer)
print("Player wins, 1 point for the player")
players += 1
elif player == options[1]:
if computer == options[2]:
print(computer, "cuts", player)
print("Player lost, 1 point for the computer")
computers += 1
else:
print(player, 'covers', computer)
print("Player wins, 1 point for the player")
players += 1
elif player == options[2]:
if computer == options[1]:
print(computer, "smashes", player)
print("Player lost, 1 point for the computer")
computers += 1
else:
print(player, "cuts", computer)
print("Player wins, 1 point for the player")
players += 1
rounds-=1 # dcrease the rounds left
if playerplay:
print((f'Player {players}\nComputer {computers}') )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.