Skip to content

Added game with copilot #5

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 2 commits 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
55 changes: 55 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import random

def get_player_choice():
while True:
choice = input("Choose rock, paper, or scissors: ").lower()
if choice in ['rock', 'paper', 'scissors']:
return choice
else:
print("Invalid choice. Please try again.")

def get_computer_choice():
return random.choice(['rock', 'paper', 'scissors'])

def play_round(player_choice, computer_choice):
print(f"Player chooses: {player_choice}")
print(f"Computer chooses: {computer_choice}")

if player_choice == computer_choice:
print("It's a tie!")
return 'tie'
elif (player_choice == 'rock' and computer_choice == 'scissors') or \
(player_choice == 'paper' and computer_choice == 'rock') or \
(player_choice == 'scissors' and computer_choice == 'paper'):
print("Player wins!")
return 'win'
else:
print("Computer wins!")
return 'loss'

def play_game():
player_score = 0
computer_score = 0

while True:
player_choice = get_player_choice()
computer_choice = get_computer_choice()

result = play_round(player_choice, computer_choice)

if result == 'win':
player_score += 1
elif result == 'loss':
computer_score += 1

print(f"Player score: {player_score}")
print(f"Computer score: {computer_score}")

play_again = input("Do you want to play again? (yes/no): ").lower()
if play_again != 'yes':
break

print("Game over!")
print(f"Final score: Player {player_score} - Computer {computer_score}")

play_game()