Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Elif syntaxerror
#1
my code here
I 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?
Reply
#2
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!
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Apr-04-2017, 02:36 PM)James2929 Wrote:
my code here

What did you expect this to be for?
Recommended Tutorials:
Reply
#4
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?
Reply
#5
You are incorrectly using the or statement. Documentation

You 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":
Reply
#6
this is a common fall point for new users
https://python-forum.io/Thread-Multiple-...or-keyword
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Whats the right way to refactor this Big if/elif/elif ? pitosalas 1 2,257 Jul-28-2019, 05:52 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020