Skip to content

minigame #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import random

def is_valid_choice(choice, options):
"""Check if a choice is valid based on the available options."""
return choice in options

def is_winning_choice(choice, opponent_choice):
"""Check if a choice beats another choice."""
if (choice == "rock" and opponent_choice == "scissors") or \
(choice == "paper" and opponent_choice == "rock") or \
(choice == "scissors" and opponent_choice == "paper"):
return True
return False

def main():
"""Main game loop."""
player_score = 0
computer_score = 0
options = ["rock", "paper", "scissors"]

while True:
# Get player's choice
player_choice = input("Enter your choice (rock, paper, scissors): ").lower()

# Validate player's choice
if not is_valid_choice(player_choice, options):
print("Invalid choice. Please try again.")
continue

# Get computer's choice
computer_choice = random.choice(options)

# Display choices
print(f"Player chose {player_choice} and computer chose {computer_choice}.")

# Determine the winner
if player_choice == computer_choice:
print("It's a tie!")
elif is_winning_choice(player_choice, computer_choice):
print("Player wins!")
player_score += 1
else:
print("Computer wins!")
computer_score += 1

# Display scores
print(f"Player score: {player_score} | Computer score: {computer_score}")

# Ask if the player wants to play again
play_again = input("Do you want to play again? (yes/no) ").lower()

# Exit the game loop if the player doesn't want to play again
if play_again != "yes":
break

# Display final scores
print(f"Player score: {player_score} | Computer score: {computer_score}")

if __name__ == "__main__":
main()