Game Not Functioning Properly - python

So i tried making a rock paper scissors game but some if statements are not working. code was written in python.
Is there something preventing the if statements ffrom running? or s there another problem
I tried a bunch of little changes but none of them work
code:
import random
moves = ('rock', 'paper', 'scissors')
while True:
print("rock, paper, scissors. Go! ")
userInput = input("Choose your move: ")
botInput = random.choice(moves)
if userInput == botInput:
print(userInput + " VS " + botInput)
print("DRAW")
if userInput == "paper" and botInput == "rock":
print(userInput + " VS " + botInput)
print("Player Wins!")
if userInput == "scissors" and botInput == "paper":
print(userInput + " VS " + botInput)
print("Player Wins!")
if userInput == "rock" and botInput == "scissors":
print(userInput + " VS " + botInput)
print("Player Wins!")
if userInput == "rock" and botInput == "paper":
print(userInput + " VS " + botInput)
print("Bot Wins!")
if userInput == "paper" and botInput == "scissors":
print(userInput + " VS " + botInput)
print("Bot Wins!")
if userInput == "scissors" and botInput == "rock":
print(userInput + " VS " + botInput)
print("Bot Wins!")
print("Wanna Rematch?")
decision = input("Yes or No? ")
if decision == "Yes":
pass
elif decision == "No":
break

Here's my solution to this. I cleaned up the amount of if-else statements in your code as well with a variable outcome_map. I also removed a lot of the typing rarities that come with inputs by introducing your choice to be "(1, 2, or 3)":
import random
moves = ('rock', 'paper', 'scissors')
while True:
print("Rock, paper, scissors. Go! ")
user_input = int(input("Choose your move (1:rock, 2:paper, 3:scissors): "))
if user_input not in [1, 2, 3]:
print("Invalid input. Try again...")
continue
bot_move = random.choice(moves)
user_move = moves[user_input-1]
outcome_map = { # item A vs item B -> Outcome for A
"rock":{
"rock":"Draw",
"paper":"Lose",
"scissors":"Win",
},
"paper":{
"rock":"Win",
"paper":"Draw",
"scissors":"Lose",
},
"scissors":{
"rock":"Lose",
"paper":"Win",
"scissors":"Draw",
}
}
outcome = outcome_map[user_move][bot_move]
print("Player: ", outcome, "!")
decision = input("Wanna Rematch? (y/n) ")
if decision in ["y", "yes", "Y", "YES"]:
pass
else:
print("Exiting... ")
break
Hope this helps!

I think there's nothing wrong with your code... however, it does not handle specific inputs, maybe that is your problem, here is my solution:
import random
moves = ('rock', 'paper', 'scissors')
while True:
print("rock, paper, scissors. Go! ")
userInput = input("Choose your move: ").lower()
botInput = random.choice(moves)
#check if input is valid
if userInput not in moves:
print("Choose a valid move! Wanna try again?")
decision = input("Yes or No? ").lower()
if decision == "yes" or decision == 'y': continue
# skips the remaining body of the loop
else: break
elif userInput == botInput:
print(userInput + " VS " + botInput)
print("DRAW")
elif userInput == "paper" and botInput == "rock":
print(userInput + " VS " + botInput)
print("Player Wins!")
elif userInput == "scissors" and botInput == "paper":
print(userInput + " VS " + botInput)
print("Player Wins!")
elif userInput == "rock" and botInput == "scissors":
print(userInput + " VS " + botInput)
print("Player Wins!")
elif userInput == "rock" and botInput == "paper":
print(userInput + " VS " + botInput)
print("Bot Wins!")
elif userInput == "paper" and botInput == "scissors":
print(userInput + " VS " + botInput)
print("Bot Wins!")
elif userInput == "scissors" and botInput == "rock":
print(userInput + " VS " + botInput)
print("Bot Wins!")
print("Wanna Rematch?")
decision = input("Yes or No? ").lower()
if decision == "yes" or decision == 'y': continue
else: break

I hope you understand what I did here:
moves = ('rock', 'paper', 'scissors')
decision = "Nothing"
while decision != "No":
decision = "Nothing"
print("rock, paper, scissors. Go! ")
userInput = input("Choose your move: ")
botInput = random.choice(moves)
if userInput == "paper":
if botInput == "rock":
print(userInput + " VS " + botInput)
print("Player Wins!")
elif botInput == "paper":
print(userInput + " VS " + botInput)
print("DRAW")
elif botInput == "scissors":
print(userInput + " VS " + botInput)
print("Bot Wins!")
else:
print("Invalid choice.")
if userInput == "scissors":
if botInput == "rock":
print(userInput + " VS " + botInput)
print("Bot Wins!")
elif botInput == "paper":
print(userInput + " VS " + botInput)
print("Player Wins!")
elif botInput == "scissors":
print(userInput + " VS " + botInput)
print("DRAW")
if userInput == "rock":
if botInput == "rock":
print(userInput + " VS " + botInput)
print("DRAW")
elif botInput == "paper":
print(userInput + " VS " + botInput)
print("Bot Wins!")
elif botInput == "scissors":
print(userInput + " VS " + botInput)
print("Player Wins!")
while decision != "Yes" and decision != "No":
print("Wanna Rematch?")
decision = input("Yes or No? ")
if decision == "Yes":
pass
elif decision == "No":
break
else:
print("Invalid answer.")

Related

Rock Paper Scissors function not showing up

The function is not working and therefore my score is not adding. I would like to run this just like a normal rock paper scissors game. It would be highly appreciated if you are able to solve this problem.
import random
user_score = 0
computer_score = 0
def Choose_Option():
user_choice = input("Choose Rock, Paper, Scissors: ")
if user_choice in ["Rock", "rock", "r", "R"]:
user_choice = "r"
elif user_choice in ["Paper", "paper", "p", "P"]:
user_choice = "p"
elif user_choice in ["Scissors", "scissors", "s", "S"]:
user_choice = "s"
else:
print("I don't understand. Try Again")
Choose_option()
return user_choice
def Computer_Option():
computer_choice = random.randint(1,3)
if computer_choice == 1:
computer_choice == "r"
elif computer_choice == 2:
computer_choice == "p"
else:
computer_choice == "s"
return computer_choice
while True:
print("")
user_choice = Choose_Option()
computer_choice = Computer_Option()
print("")
if user_choice == "r":
if computer_choice == "r":
print("You choose rock. Computer choose rock. Tied")
elif computer_choice == "p":
print("You choose rock. Computer choose paper. You Lose")
computer_score += 1
elif computer_choice == "s":
print("You choose rock. Computer choose scissors. You Win")
user_score += 1
elif user_choice == "p":
if computer_choice == "p":
print("You choose paper. Computer choose paper. Tied")
elif computer_choice == "r":
print("You choose paper. Computer choose rock. You Win")
user_score += 1
elif computer_choice == "s":
print("You choose paper. Computer choose scissors. You lose")
computer_score += 1
elif user_choice == "s":
if computer_choice == "s":
print("You choose scissors. Computer choose scissors. Tied")
elif computer_choice == "r":
print("You choose scissors. Computer choose rock. You lose")
computer_score += 1
elif computer_choice == "p":
print("You choose scissors. Computer choose paper. You win")
user_score += 1
print("")
print("Player wins: " + str(user_score))
print("Computer wins: " + str(computer_score))
print("")
user_choice = input("Do you want to play again? (y/n)")
if user_choice in ["Y", "y", "yes", "Yes", "YES"]:
pass
elif user_choice in ["N", "NO", "no", "No", "n"]:
break
else:
break
I liked this problem. Try posting it in github as well.
Here are some improvements that I made it.
import random
user_score = 0
computer_score = 0
def Choose_Option():
user_choice = input("Choose Rock, Paper, Scissors: ")
user_choice=user_choice.lower()
if user_choice in ["rock", "r"]:
user_choice = "r"
elif user_choice in ["paper", "p"]:
user_choice = "p"
elif user_choice in ["scissors", "s"]:
user_choice = "s"
else:
print("I don't understand. Try Again")
Choose_Option()
return user_choice
def Computer_Option():
computer_choice = random.randint(1,3)
dict_option = {
1:'r'
,2:'p'
,3:'s'
}
computer_choice=dict_option.get(computer_choice)
return computer_choice
while True:
print("")
user_choice = Choose_Option()
computer_choice = Computer_Option()
print("")
dict_rule={
'p':'r',
's':'p',
'r':'s'
}
dict_name={
'p':'Paper',
's':'Scissor',
'r':'Rock'
}
if user_choice==computer_choice:
print(f"You choose {dict_name[user_choice]}. Computer choose {dict_name[computer_choice]}. Tied")
elif dict_rule[user_choice] == computer_choice:
print(f"You choose {dict_name[user_choice]}. Computer choose {dict_name[computer_choice]}. You Win")
user_score += 1
else:
print(f"You choose {dict_name[user_choice]}. Computer choose {dict_name[computer_choice]}. You Lose")
computer_score += 1
print("")
print("Player wins: " + str(user_score))
print("Computer wins: " + str(computer_score))
print("")
user_choice = input("Do you want to play again? (y/n)")
user_choice=user_choice.lower()
if user_choice in ["y", "yes"]:
pass
elif user_choice in ["no","n"]:
break
else:
break

Variable not registering change in value

I wanted to make a simple Rock, Paper, Scissor game in Python. It goes well with the game, but the final scores are always being showed as a 0.
I wanted to show a smaller section of the code but, I don't know where the problem lies, so I am sorry for the length of the code.
I am still a novice learner, so please pardon me if the question is too silly or the code is not well formatted.
#Rock-Paper-Scissor Game
import random
print("Please enter your name:")
userName = input()
print("Welcome " + userName)
print("The following are the rules of the game:")
print("Press 'R' for Rock")
print("Press 'P' for Paper")
print("Press 'S' for Scissor")
print("This will be a 10 point match")
userTally = 0
compTally = 0
def gameProcess(userTally, compTally): #The process of the game. It increments or decrements the value depending on the result
print("Your turn:")
userInput = input()
computerChoice = random.choice(["R","P","S"])
if userInput == "R": #User Inputs R for Rock
if computerChoice == "R":
print("The computer chose Rock")
print("It's a Tie")
elif computerChoice == "P":
print("The computer chose Paper")
print("Computer Won")
compTally = compTally + 1
elif computerChoice == "S":
print("The computer chose Scissor")
print("You Won")
userTally = userTally + 1
elif userInput == "P": #User Inputs P for Paper
if computerChoice == "R":
print("The computer chose Rock")
print("You Won")
userTally = userTally + 1
elif computerChoice == "P":
print("The computer chose Paper")
print("It's a Tie")
elif computerChoice == "S":
print("The computer chose Scissor")
print("Computer Won")
compTally = compTally + 1
elif userInput == "S": #User Inputs S for Scissor
if computerChoice == "R":
print("The computer chose Rock")
print("Computer Won")
compTally = compTally + 1
elif computerChoice == "P":
print("The computer chose Paper")
print("You Won")
userTally = userTally + 1
elif computerChoice == "S":
print("The computer chose Scissor")
print("It's a Tie")
return(userTally,compTally)
def tryCount(): #The number of tries....
tryNum = 1
while tryNum < 11:
gameProcess(0, 0)
tryNum = tryNum + 1
tryCount()
print("You scored " + str(userTally))
print("The computer scored " + str(compTally))
if userTally > compTally:
print("CONGRATULATIONS, YOU WON.")
elif userTally < compTally:
print("Sorry, better luck next time.")
close = input()
if close == "Random Input.":
exit()
else:
exit()
You pass 0, 0 to gameProcess, which you treat as the scores within the function, and then return them modified, but you do not actually use the return value in the only place you call gameProcess (in tryCount), so the global userTally, compTally variables remain unchanged.
This is how you should change tryCount:
def tryCount(): #The number of tries....
global userTally, compTally
tryNum = 1
while tryNum < 11:
userTally,compTally=gameProcess(userTally,compTally)
tryNum = tryNum + 1

Can't convert 'int' object to str implicitly?

I am making rock paper scissors and when I run it it says "Can't convert 'int' object to str implicitly".
import time
import random
print("Do you want to play rock, paper, scissors?")
playerscore = 0
cpuscore = 0
game = input()
game = game.upper()
while game == "SURE" or game == "YES" or game == "YEAH": # starts rock paper scissors
number = random.randint(1, 3)
if number == 1:
cpurpors = "SCISSORS"
elif number == 2:
cpurpors = "ROCK"
elif number == 3:
cpurpors = "PAPER"
print("Cool! Rock, paper or scissors?")
rpors = input()
rpors = rpors.upper()
print("Rock")
time.sleep(.5)
print("Paper")
time.sleep(.5)
print("Scissors")
time.sleep(.5)
print(cpurpors + "!")
time.sleep(.5)
if cpurpors == rpors:
print("Draw!")
elif cpurpors == "SCISSORS" and rpors == "PAPER" or cpurpors == "PAPER" and rpors == "ROCK" or cpurpors == "ROCK" and rpors == "SCISSORS":
cpuscore = cpuscore + 1
print("Haha, I win!")
elif rpors == "SCISSORS" and cpurpors == "PAPER" or rpors == "PAPER" and cpurpors == "ROCK" or rpors == "ROCK" and cpurpors == "SCISSORS":
playerscore = playerscore + 1
print("Oh no! You win!")
print("The scores are:")
print("Guiseppebot: " + cpuscore)
print(name + ": " + playerscore)
print("Would you like to play again?")
game = input()
game = game.upper()
The problem is that you're adding int variables to the print statements. Try doing something like this:
print(name + ": " + str(playerscore))
In that example, you're setting playerscore to the string version of the int.
Need to wrap the integers cpuscore and playerscore with str to convert them to a string, as it won't do it implicitly.
print("Guiseppebot: " + str(cpuscore))
print(name + ": " + str(playerscore))
Another nice option is using format, which does call str on objects for you so you don't have to worry about it in the future:
print("Guiseppebot: {}".format(cpuscore))
print("{}: {}".format(name, playerscore))
str is the built-in function that will convert non string objects to a string. It does this by calling the objects .__str__ method if it exists (and knows how to otherwise for objects like ints and floats.) Read more about it in the docs here https://docs.python.org/3/library/stdtypes.html#str
I'm nor sure if this is the best solution, but my approach would be to use str() to convert the integer (cpuscore) to a string.
import time
import random
name = input ("what's your name? ") #added in input for variable (name)
print("Do you want to play rock, paper, scissors?")
playerscore = 0
cpuscore = 0
game = input()
game = game.upper()
while game == "SURE" or game == "YES" or game == "YEAH": # starts rock paper scissors
number = random.randint(1, 3)
if number == 1:
cpurpors = "SCISSORS"
elif number == 2:
cpurpors = "ROCK"
elif number == 3:
cpurpors = "PAPER"
print("Cool! Rock, paper or scissors?")
rpors = input()
rpors = rpors.upper()
print("Rock")
time.sleep(.5)
print("Paper")
time.sleep(.5)
print("Scissors")
time.sleep(.5)
print(cpurpors + "!")
time.sleep(.5)
if cpurpors == rpors:
print("Draw!")
elif cpurpors == "SCISSORS" and rpors == "PAPER" or cpurpors == "PAPER" and rpors == "ROCK" or cpurpors == "ROCK" and rpors == "SCISSORS":
cpuscore = cpuscore + 1
print("Haha, I win!")
elif rpors == "SCISSORS" and cpurpors == "PAPER" or rpors == "PAPER" and cpurpors == "ROCK" or rpors == "ROCK" and cpurpors == "SCISSORS":
playerscore = playerscore + 1
print("Oh no! You win!")
print("The scores are:")
print("Guiseppebot: " + str(cpuscore)) #converted cpuscore to a string
print(name + ": " + str(playerscore)) #variable (name) wasn't declared
print("Would you like to play again?")
game = input()
game = game.upper()
cpuscore is an integer(int) it can't be concatenated with a string. Python doesn't convert it to a string automatically("implicitly"). So you at least need to do:
print("Guiseppebot: " + str(cpuscore))
Even better/easier, in Python 3.6+, use f-strings
Assuming you can put the value inside a variable into a string (integers, strings, lists, dictionaries are ok), you just put them inside curly brackets.
Here's how the line with that error looks with f-strings:
print(f"Guiseppebot: {cpuscore}")

python problems can't seem to check some values

I have just started my first language: python. So I started practicing it and tried writing a rock, paper, scissors game. I know I'm not the best but can't seem to make the game end when the us_count and comp_count reached the max
import random
us_count = 0
comp_count = 0
gamelim = None
def GameConfig(gamelim,us_count,comp_count):
gamelim = input("How long do you want the game to be: \n")
Game(gamelim,us_count,comp_count)
def GameLoop(gamelim,us_count,comp_count):
if us_count > comp_count and us_count + comp_count == gamelim:
print("You have the best ",us_count," out of ",gamelim)
GameEnd()
elif us_count < comp_count and us_count + comp_count == gamelim:
print("Computer has bested ",comp_count," out of ",gamelim)
GameEnd()
elif us_count == comp_count and us_count + comp_count == gamelim:
print("Game tied.")
GameEnd()
else:
Game(gamelim,us_count,comp_count)
def GameEnd():
gamecont = print("Game has ended do you want to play again?")
end
def Game(gamelim,us_count,comp_count):
us_choice = str(input("Please select rock, paper or scissors: \n"))
choices = ["rock","paper","scissors"]
comp_choice = random.choice(choices)
if us_choice == comp_choice:
print("Computer choses " + comp_choice + "\nIt'a tie.")
elif us_choice == "rock" and comp_choice == "scissors":
print("Computer choses " + comp_choice + "\nYou won.")
us_count = us_count + 1
elif us_choice == "rock" and comp_choice == "paper":
print("Computer choses " + comp_choice + "\nYou lost.")
comp_count = comp_count + 1
elif us_choice == "paper" and comp_choice == "rock":
print("Computer choses " + comp_choice + "\nYou won.")
us_coun = us_count + 1
elif us_choice == "paper" and comp_choice == "scissors":
print("Computer choses " + comp_choice + "\nYou lost.")
comp_count = comp_count + 1
elif us_choice == "scissors" and comp_choice == "paper":
print("Computer choses " + comp_choice + "\nYou won.")
us_count = us_count + 1
elif us_choice == "scissors" and comp_choice == "rock":
print("Computer choses " + comp_choice + "\nYou lost.")
comp_count = comp_count + 1
else:
print("Please enter a corret value")
GameLoop(gamelim,us_count,comp_count)
GameConfig(gamelim,us_count,comp_count)

Rock Paper Scissors Python Program

I'm trying to write a Rock, Paper Scissors program with Python but I keep getting this error and I'm not sure how to fix it.
File "C:\Python33\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 140, in <module>
File "C:\Python33\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 34, in main
builtins.TypeError: 'tuple' object is not callable
This is my program:
import random
def main():
win = 0
lose = 0
tie = 0
ROCK_CHOICE = '1'
PAPER_CHOICE = '2'
SCISSORS_CHOICE = '3'
QUIT_CHOICE = '4'
play_again = 'y'
while play_again == 'y':
print('Welcome to the game of paper, rock, scissors!')
print('Please input the correct number according')
print('to the choices given.')
computer_choice = get_computer_choice()
player_choice = get_player_choice()
determine_winner = (computer_choice, player_choice)
print('Computer choose', computer_choice, '.')
print('You choose', player_choice, '.')
determine_winner(computer_choice, player_choice)
if result == -1:
lose += 1
elif result == 0:
tie += 1
else:
win += 1
play_again = input('Play again? Enter y for yes')
def get_computer_choice():
choice = random.randint(1,4)
if choice == 1:
choice = 'ROCK'
elif choice == 2:
choice = 'PAPER'
elif choice == 3:
choice = 'SCISSORS'
else:
choice = 4
return choice
def get_player_choice():
choice = int(input('Select rock(1), paper(2), or scissors(3): '))
while choice != 1 and choice != 2 and choice != 3:
print('The valid numbers are rock choice 1), paper choice 2),')
print('or scissors choice 3).')
choice = int(input('Please a valid number: '))
if choice == 1:
choice = 'ROCK'
elif choice == 2:
choice = 'PAPER'
elif choice == 3:
choice = 'SCISSORS'
else:
choice = 4
return choice
def determine_winner(computer_choice, player_choice):
if player_choice == ROCK_CHOICE and computer_choice == ROCK_CHOICE:
print('Its a tie.')
return 0
elif player_choice == PAPER_CHOICE and computer_choice == PAPER_CHOICE:
print('Its a tie.')
return 0
elif player_choice == SCISSORS_CHOICE and computer_choice == SCISSORS_CHOICE:
print('Its a tie.')
return 0
elif player_choice == ROCK_CHOICE and computer_choice == PAPER_CHOICE:
print('You lose, Rock covers Paper.')
return -1
elif player_choice == ROCK_CHOICE and computer_choice == SCISSORS_CHOICE:
print('You WIN!!! Rock smashes Scissors.')
return 1
elif player_choice == PAPER_CHOICE and computer_choice == SCISSORS_CHOICE:
print('You lose, Scissors cuts Paper.')
return -1
elif player_choice == SCISSORS_CHOICE and computer_choice == ROCK_CHOICE:
print('You lose, Rock smashes Paper.')
return -1
elif player_choice == SCISSORS_CHOICE and computer_choice == PAPER_CHOICE:
print('You WIN!!! Scissors cuts Paper.')
return 1
elif player_choice == PAPER_CHOICE and computer_choice == ROCK_CHOICE:
print('You WIN!!! Paper covers Rock.')
return 1
else:
player_choice == QUIT_CHOICE
print('Exiting the program...')
return
def display_results():
print()
print(' MENU')
print('1) Rock')
print('2) Paper')
print('3) Scissors')
print('4) Quit')
player_choice = input('Enter your choice:')
while player_choice != '1' and player_choice != '2' and \
player_choice != '3' and player_choice != '4':
print()
print('Error: invalid selection.')
player_choice = input('Please re-enter your choice:')
print('Your total wins are', win, '.')
print('Your total losses are', lose, '.')
print('Your total ties are', tie, '.')
main()
input('\nPress ENTER to continue...')
error 1:
fix line27 : result = determine_winner(computer_choice, player_choice
error 2:
if player_choice == ROCK_CHOICE and computer_choice == ROCK_CHOICE:
NameError: global name 'ROCK_CHOICE' is not defined
move:
ROCK_CHOICE = '1'
PAPER_CHOICE = '2'
SCISSORS_CHOICE = '3'
QUIT_CHOICE = '4'
outside main (to line 3)
error 3:
File "main.py", line 41, in main
play_again = input('Play again? Enter y for yes')
File "<string>", line 1, in <module>
NameError: name 'y' is not defined
input should be raw_input line 41:
play_again = raw_input('Play again? Enter y for yes')
NB. and the input('\nPress ENTER to continue...') also needs to be a raw_input
NNBB. and if you plan to use display_results; there is errors in there too.
from random import randint
class RPS:
def __init__(self, pCh):
self.playChoice = pCh
self.compChoice = ""
self.choice = randint(0, 3)
self.winner = ""
self.uCompChoice = ""
self.uPlayChoice = ""
if self.choice == 0:
self.compChoice = "R"
elif self.choice == 1:
self.compChoice = "P"
else:
self.compChoice = "S"
if self.compChoice == "R":
self.uCompChoice = "Rock"
if self.compChoice == "P":
self.uCompChoice = "Paper"
if self.compChoice == "S":
self.uCompChoice = "Scissors"
if self.playChoice == "P" or self.playChoice == "p" or self.playChoice == "Paper" or self.playChoice == "paper" or self.playChoice == "PAPER" or self.playChoice == "2":
self.uPlayChoice = "Paper"
if self.playChoice == "S" or self.playChoice == "s" or self.playChoice == "Scissors" or self.playChoice == "scissors" or self.playChoice == "SCISSORS" or self.playChoice == "3":
self.uPlayChoice = "Scissors"
if self.playChoice == "R" or self.playChoice == "r" or self.playChoice == "Rock" or self.playChoice == "rock" or self.playChoice == "ROCK" or self.playChoice == "1":
self.uPlayChoice = "Rock"
def determineWinner(self):
if self.uCompChoice == self.uPlayChoice:
return "Draw Game!"
elif self.uCompChoice == "Rock":
if self.uPlayChoice == "Paper":
return "You won because Paper covers Rock!!"
else:
return "Computer wins because Rock breaks Scissors."
elif self.uCompChoice == "Paper":
if self.uPlayChoice == "Scissors":
return "You won because Rock cuts Paper!!"
else:
return "Computer wins because Paper covers Rock."
else:
if self.uPlayChoice == "Rock":
return "You won because Rock breaks Scissors!!"
else:
return "Computer wins because Scissors cuts Paper."
def __str__(self):
return "Your weapon: " + self.uPlayChoice + "\n" + "Computer's weapon " + self.uCompChoice + "\n" + \
self.determineWinner()
def main():
print("Welcome to RockPaperScissors.")
print("Pick your weapon: ")
print("1. Rock")
print("2. Paper")
print("3. Scissors")
print("Note: If you don't pick a valid weapon the computer will pick a random weapon for you")
# input from user (weapon)
weapon = input("")
# Creating a new object
attack = RPS(weapon)
# printing the result
print(attack.__str__())
# Asking the user if he wants to play again
playagain = input("Would you like to play again: \n")
if playagain == "Yes" or playagain == "yes" or playagain == "YES" or playagain == "y" or playagain == "Y":
main()
else:
print("Thank you for playing.")
main()
don't you think, this code will be shorter this way:
print("R for rock")
print("P for paper")
print("S for scissors")
choices = ["rock", "paper", "scissor"]
while True:
choice = random.choice(choices)
player_choice = input("choose> ")
if player_choice.lower() == "r":
if choice == "rock":
print("i picked rock too!")
elif choice == 'paper':
print("YOU LOST! i picked paper")
else:
print("fine, you win")
elif player_choice.lower() == "p":
if choice == "rock":
print("You win.... Whatever!")
elif choice == 'paper':
print("haha same decisions")
else:
print("I won! You should be ashamed of losing against a bot")
elif player_choice.lower() == "s":
if choice == "rock":
print("I won! Humanity will soon be controlled by bots")
elif choice == 'paper':
print("Alright, you win")
else:
print("Draw")
else:
print("YOU WANNA PLAY GAMES WITH ME!??!?!?")

Categories

Resources