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

Added a game #77

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
59 changes: 59 additions & 0 deletions General Projects/rock_papper_scissors_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Rock , papper ,scissors game:

# imported a package which generates random numbers
import random

# defined a function names gamewin between you and computer

def gamewin(comp,you):

# if you and computer chooses same value, declare a tie!
if comp == you :
return None

# check all possibilities when computer chooses Rock
elif comp == 'r' :
if you == 'p':
return True

elif you == 's' :
return False
# check all possibilities when computer chooses papper
elif comp == 'p' :
if you == 's':
return True

elif you == 'r' :
return False
# check all possibilities when computer chooses scissor
elif comp == 's' :
if you == 'r':
return True

elif you == 'p' :
return False


# printed computer turn and assigned random numbers
print("Comp Turn: rock(r) papper(p) or scissor(s)?")
randNo = random.randint(1, 3)
if randNo == 1:
comp = 'r'
elif randNo == 2:
comp = 'p'
elif randNo == 3:
comp = 's'

# given an option to choose player and declared conditions on game win,or lose
you = input("Your Turn: rock(r) papper(p) or scissor(s)?")
a = gamewin(comp, you)

print(f"Computer chose {comp}")
print(f"You chose {you}")

if a == None:
print("The game is a tie!")
elif a:
print("You Win!")
else:
print("You Lose!")