Files
tp1_codemarchantpas/rock_paper_scissor_game.py

52 lines
1.7 KiB
Python
Raw Normal View History

2025-10-14 17:58:37 +02:00
import random
def user_move() -> int:
2025-10-14 17:58:37 +02:00
return input("Enter your move (rock, paper, scissors): ")
def random_move() -> str:
return random.choice(['rock', 'paper', 'scissors',''])
2025-10-14 17:58:37 +02:00
def check_choice_validity(move: str) -> str:
valid_moves = ['rock', 'paper', 'scissor']
2025-10-14 17:58:37 +02:00
if move in valid_moves:
return move
else:
return 'Invalid move. Please choose rock, paper, or scissors.'
def check_winner(user_move: str, computer_move: str):
if user_move == computer_move :
print("IT'S A TIE!! You're both bad..") #print avant le return
2025-10-14 17:58:37 +02:00
return
elif user_move == "paper" and computer_move == "scissors":
print("YOU WIN!! You're not bad..")
return
elif user_move == "paper" and computer_move == "rock":
print("YOU LOSE!! You're bad..")
return
elif user_move == "rock" and computer_move == "scissors":
print("YOU WIN!! You're not bad..")
return
elif user_move == "rock" and computer_move == "paper":
print("YOU LOSE!! You're bad..")
return
elif user_move == "scissors" and computer_move == "paper":
print("YOU WIN!! You're not bad..")
return
elif user_move == "scissors" and computer_move == "rock":
print("YOU LOSE!! You're bad..")
return
else:
print("Erm..... Error...?")
if __name__ == '__main__':
user_choice = ''
print("Welcome to Rock, Paper, Scissors!!!!!!!!!!")
2025-10-14 17:58:37 +02:00
user_choice = user_move()
check_choice_validity(user_choice)
print("Computer is thinking very hard....")
computer_choice = random_move()
print(f"Computer chose: {user_choice}")
2025-10-14 17:58:37 +02:00
check_winner(user_choice, computer_choice)