Skip to content
Open
Show file tree
Hide file tree
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
73 changes: 73 additions & 0 deletions Rock paper scissors Game Version 1.3 Stable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import random

"""A simple Rock-Paper-Scissors game."""

# Game data
choices = ("r", "p", "s")
emojis = {"r": "🌋", "p": "📜", "s": "✂️"}
aliases = {
'r': 'r',
'rock': 'r',
'p': 'p',
'paper': 'p',
's': 's',
'scissors': 's'
}
winning_rules = {('r', 's'), ('s', 'p'), ('p', 'r')}

# Main game loop
def get_user_choice_on_playing():
while True:
mode = input("Do you want to play rock paper and scissors game (y/n): ").lower().strip()

if mode in ('n', 'no'):
print("Goodbye!")
return False
elif mode not in ("yes", "y"):
print("Please enter yes or no.")
continue
else:
return True

# Inner game loop
def get_user_choice():
while True:
user_input = input("Rock, Paper or Scissors (r/p/s): ").lower().strip()
user_choice = aliases.get(user_input)
if user_choice not in choices:
print("Invalid choice!.")
continue
else:
return user_choice

def display_choices(user_choice, computer_choice):
print(f"You chose {emojis[user_choice]} and the computer chose {emojis[computer_choice]}")

def determine_the_winner(user_choice, computer_choice):
if user_choice == computer_choice:
print("It's a tie!")
else:
result = (user_choice, computer_choice)
if result in winning_rules:
print("You win!")
else:
print("You lose!")

def play_game():
while True:
if get_user_choice_on_playing():
user_choice = get_user_choice()
computer_choice = random.choice(choices)
display_choices(user_choice, computer_choice)
determine_the_winner(user_choice, computer_choice)


# Ask if the user wants to play again
should_continue = input("Do you want to play again (y/n): ").lower().strip()
if should_continue in ('n', 'no'):
print("Goodbye!")
break # Exit the loop if the user doesn't want to play again
else:
break # Exit the loop if the user doesn't want to play initially
play_game()

3 changes: 3 additions & 0 deletions Rock, paper and scissors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user_choice = input("Rock, Paper and scissors (r/p/s): ")
if user_choice not in choices:
print("Invalid Choice ")
53 changes: 53 additions & 0 deletions Rock, paper, scissors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import random

"""A simple Rock-Paper-Scissors game."""

choices = ("r", "p", "s",)
emojis = {"r" : "🌋", "p" : "📜", "s" : "✂️"}
normalised_choices = {
'r': 'r',
"rock": "r",
'paper': "p",
"p": "p",
"scissors": "s",
"s": "s"
}
winning_rules = {('r', 's'), ('s', 'p'), ('p', 'r')}

while True:
mode = input("Do you want to play rock paper and scissors game (y/n): ").lower().strip()

if mode in ('n', 'no'):
print("Goodbye!")
break
if mode not in ("yes", "y"):
print("Enter yes or no, Please")
continue
while True:

user_choice = input("Rock, Paper and Scissors (r/p/s): ").lower().strip()
if user_choice not in choices:
user_choice = (normalised_choices[user_choice])

break
else:
print("Invalid Choice, please pick one of: r, p, s")

computer_choice = random.choice(choices)
print(f"You choose {emojis[user_choice]} and computer choose {emojis[computer_choice]}")

if user_choice == computer_choice:
print("So it's a tie")
else:
result = (user_choice, computer_choice)
if result in winning_rules:
print("You win")
else:
print("You lost")
print("More innovation coming soon")






13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rock import get_user_choice, get_user_choice_on_playing, determine_the_winner, generate_computer_choice
while True:
if get_user_choice_on_playing():
user_choice = get_user_choice()
computer_choice = generate_computer_choice()
determine_the_winner(user_choice, computer_choice)

should_continue = input("Do you want to play again (y/n): ").lower().strip()
if should_continue in ('n', 'no'):
print("Goodbye!")
break
else:
break
73 changes: 73 additions & 0 deletions rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import random

"""A simple Rock-Paper-Scissors game."""

# Game data
choices = ("r", "p", "s")
emojis = {"r": "🌋", "p": "📜", "s": "✂️"}
aliases = {
'r': 'r',
'rock': 'r',
'p': 'p',
'paper': 'p',
's': 's',
'scissors': 's'
}
winning_rules = {('r', 's'), ('s', 'p'), ('p', 'r')}

# Main game loop
def get_user_choice_on_playing():
while True:
mode = input("Do you want to play rock paper and scissors game (y/n): ").lower().strip()

if mode in ('n', 'no'):
print("Goodbye!")
return False
elif mode not in ("yes", "y"):
print("Please enter yes or no.")
continue
else:
return True

# Inner game loop
def get_user_choice():
while True:
user_input = input("Rock, Paper or Scissors (r/p/s): ").lower().strip()
user_choice = aliases.get(user_input)
if user_choice not in choices:
print("Invalid choice!.")
continue
else:
return user_choice

def display_choices(user_choice, computer_choice):
print(f"You chose {emojis[user_choice]} and the computer chose {emojis[computer_choice]}")

def determine_the_winner(user_choice, computer_choice):
if user_choice == computer_choice:
print("It's a tie!")
else:
result = (user_choice, computer_choice)
if result in winning_rules:
print("You win!")
else:
print("You lose!")

def play_game():
while True:
if get_user_choice_on_playing():
user_choice = get_user_choice()
computer_choice = random.choice(choices)
display_choices(user_choice, computer_choice)
determine_the_winner(user_choice, computer_choice)


# Ask if the user wants to play again
should_continue = input("Do you want to play again (y/n): ").lower().strip()
if should_continue in ('n', 'no'):
print("Goodbye!")
break # Exit the loop if the user doesn't want to play again
else:
break # Exit the loop if the user doesn't want to play initially
play_game()

16 changes: 16 additions & 0 deletions rock_paper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import random

# Store game data
emojis = {"r": "🌋", "p": "📜", "s": "✂️"}
choices = ("r", "p", "s")
results = {
("r", "s"): "You win! Rock crushes Scissors!",
("s", "p"): "You win! Scissors cut Paper!",
("p", "r"): "You win! Paper covers Rock!",
("s", "r"): "You lose! Rock crushes Scissors!",
("p", "s"): "You lose! Scissors cut Paper!",
("r", "p"): "You lose! Paper covers Rock!"
}

while True:
user_choice = input("Do you want to play (y/n): ").lower().strip()
43 changes: 43 additions & 0 deletions rock_paper_scissors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Store all data needed for the game
import random

emojis = {
"r" : "🌋", "p" : "📜", "s" : "✂️"
}
choices = ("r", "p", "s")
results = {
("r", "s"): "You win! Rock crushes Scissors!",
("s", "p"): "You win! Scissors cut Paper!",
("p", "r"): "You win! Paper covers Rock!",
("s", "r"): "You lose! Rock crushes Scissors!",
("p", "s"): "You lose! Scissors cut Paper!",
("r", "p"): "You lose! Paper covers Rock!"
}

# Ask users if they want to play
while True:
user_choice = input("Do you want to play (y/n): ").lower().strip()
if user_choice in ("n" or "no"):
print("Goodbye 👋👋👋😘😘")
break
while True:

elif user_choice in ("y" or "yes"):
user_move = input("Rock, Paper, Scissors(r, p, s): ").lower().strip()
if user_move not in choices:
print("Invalid choice, press r for rock, p for paper, s for scissors")
else :
print("Please, Type only yes or no")
computer_move = random.choice(choices)
if user_move == computer_move:
print("It a Tie")
print(results[(user_move, computer_move)])
# Validate answers for errors(non words and number)

# Generate computer answers

# print result

# print the winner or loser

# Allow user to terminate the program