2 changed files with 75 additions and 0 deletions
@ -0,0 +1,54 @@
|
||||
import random |
||||
|
||||
def play_round(): |
||||
choices = ["rock", "paper", "scissors"] |
||||
computer_choice = random.choice(choices) |
||||
|
||||
while True: |
||||
user_choice = input("Enter rock, paper, or scissors: ").lower() |
||||
if user_choice in choices: |
||||
break |
||||
else: |
||||
print("Invalid choice. Please enter rock, paper, or scissors.") |
||||
|
||||
print(f"You chose: {user_choice}") |
||||
print(f"Computer chose: {computer_choice}") |
||||
|
||||
if user_choice == computer_choice: |
||||
print("It's a tie!") |
||||
return 0 |
||||
elif ( |
||||
(user_choice == "rock" and computer_choice == "scissors") |
||||
or (user_choice == "paper" and computer_choice == "rock") |
||||
or (user_choice == "scissors" and computer_choice == "paper") |
||||
): |
||||
print("You win!") |
||||
return 1 |
||||
else: |
||||
print("You lose!") |
||||
return -1 |
||||
|
||||
def main(): |
||||
user_score = 0 |
||||
computer_score = 0 |
||||
|
||||
print("Welcome to Rock, Paper, Scissors!") |
||||
|
||||
while True: |
||||
result = play_round() |
||||
if result == 1: |
||||
user_score += 1 |
||||
elif result == -1: |
||||
computer_score += 1 |
||||
|
||||
print(f"Your score: {user_score}, Computer score: {computer_score}") |
||||
|
||||
play_again = input("Play again? (yes/no): ").lower() |
||||
if play_again != "yes": |
||||
break |
||||
|
||||
print("Thanks for playing!") |
||||
print(f"Final score. Your score: {user_score}, Computer score: {computer_score}") |
||||
|
||||
if __name__ == "__main__": |
||||
main() |
@ -0,0 +1,21 @@
|
||||
num1 = float(input("Enter first number: ")) |
||||
num2 = float(input("Enter second number: ")) |
||||
operator = input("Enter operator (+, -, *, /): ") |
||||
|
||||
if operator == '+': |
||||
result = num1 + num2 |
||||
elif operator == '-': |
||||
result = num1 - num2 |
||||
elif operator == '*': |
||||
result = num1 * num2 |
||||
elif operator == '/': |
||||
if num2 == 0: |
||||
print("Error: Division by zero") |
||||
else: |
||||
result = num1 / num2 |
||||
else: |
||||
print("Invalid operator") |
||||
result = None |
||||
|
||||
if result is not None: |
||||
print("Result:", result) |
Loading…
Reference in new issue