Skip to content
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

Main #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Main #27

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

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

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

def determine_winner(user_choice, computer_choice):
if user_choice == computer_choice:
return "Tie"
elif (user_choice == "rock" and computer_choice == "scissors") or \
(user_choice == "paper" and computer_choice == "rock") or \
(user_choice == "scissors" and computer_choice == "paper"):
return "You win"
else:
return "You lose"

def play_game():
user_score = 0
computer_score = 0

while True:
user_choice = get_user_choice()
computer_choice = get_computer_choice()

print(f"You chose: {user_choice}")
print(f"The computer chose: {computer_choice}")

result = determine_winner(user_choice, computer_choice)
print(result)

if result == "You win":
user_score += 1
elif result == "You lose":
computer_score += 1

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

print(f"Final score: You {user_score} - Computer {computer_score}")

play_game()