Apr-04-2017, 02:36 PM
my code hereI have made a Rock Paper Scissors game in python using if elif and else statements.
However, when I use an elif it comes up with a syntaxerror! Any ideas?
my code hereI have made a Rock Paper Scissors game in python using if elif and else statements.
(Apr-04-2017, 02:36 PM)James2929 Wrote: [ -> ]my code here
import random computer = random.random() #set player to False player = False while player == False: if computer <= .33: computer = "Rock" elif computer <= .66: computer = "Paper" else: computer = "Scissors" player = input("Rock, Paper, Scissors?") if player == computer: print("Tie!") elif player == "Rock" or "rock": if computer == "Paper": print("You lose!", computer, "covers", player) else: print("You win!", player, "smashes", computer) elif player == "Paper" or "paper": if computer == "Scissors": print("You lose!", computer, "cut", player) else: print("You win!", player, "covers", computer) elif player == "Scissors" or "scisssors": if computer == "Rock": print("You lose...", computer, "smashes", player) else: print("You win!", player, "cut", computer) else: print("That's not a valid play. Check your spelling!") #player was set to True, but we want it to be False so the loop continues player = False computer = random.random()if i type in any random letters it doesnt come up with 'That's not valid' but just carries on running. any ideas?
or
statement. Documentationelif player == "Paper" or player == "paper"another way of over coming this is by using
lower()
which would accept all instances of "player" are return it in lower case. This way even if the user enter Rock, ROCK, RocK python would return it always in smaller case rock.elif player.lower() == "paper":