Error in writing the rock paper scissors game in python

154 Views Asked by At

I was trying to write the simple code of rock paper scissors game and this is the complete code but it is showing a EOF error in a line player = int(raw_input("Choose from 1-3: ")) . Can you please help me?? Thank you

import random 

from time import sleep 
from random import choice

print "Please select: " 
print "1  Rock" 
print "2  Paper" 
print "3  Scissors" 

player = int(raw_input("Choose from 1-3: ")) 
cpu_choice =random.choice(range(1, 4))

if player == 1:
    print "You choose Rock"
    if cpu_choice == 2:
        print "CPU choosed Paper" 
        print "You lose!!:("
    elif cpu_choice == 1:
        print "CPU choosed rock"
        print "Oh!! its a draw game"
    else :
        print "CPU choosed scissors"
        print "You win :)"

elif player == 2:
    print "You choose Paper"
    if cpu_choice == 3:
        print "CPU choosed scissors" 
        print "You lose!!:("
    elif cpu_choice == 2:
        print "CPU choosed paper"
        print "Oh!! its a draw game"
    else :
        print "CPU choosed rock"
        print "You win :)"

elif player == 3:
    print "You choose Scissors" 
    if cpu_choice == 1:
        print "CPU choosed rock" 
        print "You lose!!:("
    elif cpu_choice == 3:
        print "CPU choosed scissors"
        print "Oh!! its a draw game"
    else :
       print "CPU choosed paper"

        print "You win :)"
else :print "Enter the correct choice" 
1

There are 1 best solutions below

1
On

You haven't finish your program: there's nothing if the last if statement, so the Python interpreter fails. You have to put at least one instruction to fill the block. If you want to do nothing in this block at the moment (for example during the development, for debug), you can pute the pass statement which does strictly nothing.

if player == 1:
    print "You choose Rock"
    if cpu_choice == 2:
        pass

EDIT: I see also some indentation problems in your code, be careful about it and always uses the same amount of spaces to indent blocks.