Skip to content

"app.py" file is edited. Minigame updated #42

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

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

def get_winner(player, computer):
if player == computer:
return "tie"
elif (player == 'rock' and computer == 'scissors') or \
(player == 'scissors' and computer == 'paper') or \
(player == 'paper' and computer == 'rock'):
return "win"
else:
return "lose"

def play_game():
print("Welcome to Rock, Paper, Scissors!")

wins = 0
rounds = 0

while True:
player_choice = input("Enter your choice (rock, paper, scissors) or 'quit' to stop playing: ").lower()

if player_choice == 'quit':
print(f"Thanks for playing! You won {wins} out of {rounds} rounds.")
break
elif player_choice not in ['rock', 'paper', 'scissors']:
print("Invalid choice. Please try again.")
continue

computer_choice = get_computer_choice()
print(f"The computer chose: {computer_choice}")

result = get_winner(player_choice, computer_choice)
rounds += 1

if result == "win":
wins += 1
print("You win this round!")
elif result == "lose":
print("You lose this round.")
else:
print("It's a tie.")

print(f"Current score: {wins} wins out of {rounds} rounds.\n")

continue_playing = input("Do you want to continue playing? (yes/no): ").lower()
if continue_playing != 'yes':
print(f"Final score: You won {wins} out of {rounds} rounds.")
print("Goodbye!")
break

if __name__ == "__main__":
play_game()