Files
Python-Course/rock-paper-scissors.py
2026-08-24 13:38:36 +02:00

140 lines
4.8 KiB
Python

#############################################
# #
# Done! #
# #
#############################################
import random
import sys
import time
import os
import platform
if platform.system() == "Windows":
os.system('cls')
else:
os.system('clear')
losses = 0
wins = 0
ties = 0
while True:
if platform.system() == "Windows":
os.system('cls')
else:
os.system('clear')
print(f'''We are going to play a game of Rock, Paper, Scissors!
losses: {losses} wins: {wins} ties: {ties}''')
# Computer choice:
computer_choice = random.randint(1,3)
if computer_choice == 1:
computer_choice = 'Paper'
elif computer_choice == 2:
computer_choice = 'Rock'
elif computer_choice == 3:
computer_choice = 'Scissors'
# Player choice:
player_choice = input('What do you choose? Rock(R), Paper(P), or Scissors(S)?\n>')
if player_choice == 'P' or player_choice == 'p':
player_choice = 'Paper'
elif player_choice == 'R' or player_choice == 'r':
player_choice = 'Rock'
elif player_choice == 'S' or player_choice == 's':
player_choice = 'Scissors'
else:
print(f'The choice you made ("{player_choice}") is not valid. The program will now exit')
sys.exit()
# Playing the game:
if computer_choice == player_choice:
print('It is a tie!')
ties += 1
rematch = input('Would you like to play another game? (Y/N)\n>')
if rematch == 'y' or rematch == 'Y':
continue
elif rematch == 'n' or rematch == 'N':
print(f'''OK, thanks for playing! The final score:
wins: {wins}, losses: {losses}, ties: {ties}''')
sys.exit()
elif computer_choice == 'Rock':
if player_choice == 'Scissors':
print('You lost, you chose Scissors and the computer chose rock!')
losses += 1
rematch = input('Would you like to play another game? (Y/N)\n>')
if rematch == 'y' or rematch == 'Y':
continue
elif rematch == 'n' or rematch == 'N':
print(f'''OK, thanks for playing! The final score:
wins: {wins}, losses: {losses}, ties: {ties}''')
sys.exit()
elif player_choice == 'Paper':
print('You won, you chose scissors and the computer chose rock!')
wins += 1
rematch = input('Would you like to play another game? (Y/N)\n>')
if rematch == 'y' or rematch == 'Y':
continue
elif rematch == 'n' or rematch == 'N':
print(f'''OK, thanks for playing! The final score:
wins: {wins}, losses: {losses}, ties: {ties}''')
sys.exit()
elif computer_choice == 'Paper':
if player_choice == 'Scissors':
print('You won, you chose Scissors and the computer chose paper!')
wins += 1
rematch = input('Would you like to play another game? (Y/N)\n>')
if rematch == 'y' or rematch == 'Y':
continue
elif rematch == 'n' or rematch == 'N':
print(f'''OK, thanks for playing! The final score:
wins: {wins}, losses: {losses}, ties: {ties}''')
sys.exit()
elif player_choice == 'Rock':
print('You lost, you chose rock and the computer chose paper!')
losses += 1
rematch = input('Would you like to play another game? (Y/N)\n>')
if rematch == 'y' or rematch == 'Y':
continue
elif rematch == 'n' or rematch == 'N':
print(f'''OK, thanks for playing! The final score:
wins: {wins}, losses: {losses}, ties: {ties}''')
sys.exit()
elif computer_choice == 'Scissors':
if player_choice == 'Paper':
print('You lost, computer chose scissors and you chose paper!')
losses += 1
rematch = input('Would you like to play another game? (Y/N)\n>')
if rematch == 'y' or rematch == 'Y':
continue
elif rematch == 'n' or rematch == 'N':
print(f'''OK, thanks for playing! The final score:
wins: {wins}, losses: {losses}, ties: {ties}''')
sys.exit()
elif player_choice == 'Rock':
print('You won, computer chose scissors and you chose rock!')
wins += 1
rematch = input('Would you like to play another game? (Y/N)\n>')
if rematch == 'y' or rematch == 'Y':
continue
elif rematch == 'n' or rematch == 'N':
print(f'''OK, thanks for playing! The final score:
wins: {wins}, losses: {losses}, ties: {ties}''')
sys.exit()