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?
Elif syntaxerror
|
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?
Apr-04-2017, 02:54 PM
Hello! All we can do without the code is to look at our crystal balls and hope that we find your code there. When we see it some of us may help.
Use Python code tags, please!
Recommended Tutorials:
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?
Apr-04-2017, 03:58 PM
(This post was last modified: Apr-04-2017, 03:58 PM by alicarlos13.)
You are incorrectly using the
or statement. DocumentationYou should be using as an example: elif 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":
Apr-04-2017, 04:07 PM
this is a common fall point for new users
https://python-forum.io/Thread-Multiple-...or-keyword
Recommended Tutorials:
|
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Whats the right way to refactor this Big if/elif/elif ? | pitosalas | 1 | 2,855 |
Jul-28-2019, 05:52 PM Last Post: ichabod801 |