Python project
Python project
Learning Objectives
- Using random module for computer selection.
- Implementing conditional statements (if-elif-else) for game logic.
- Handling user input validation.
- Creating a loop for continuous gameplay.
Source Code:-
import random
def get_computer_choice():
return random.choice(['rock', 'paper', 'scissors'])
def get_user_choice():
choice = input("Enter your choice (rock, paper, scissors): ").lower()
while choice not in ['rock', 'paper', 'scissors']:
choice = input("Invalid choice. Enter rock, paper, or scissors: ").lower()
return choice
def play_game():
print("Welcome to Rock, Paper, Scissors!")
while True:
user_choice = get_user_choice()
computer_choice = get_computer_choice()