-2

我试图编写石头剪刀布游戏的简单代码,这是完整的代码,但它在 line player = int(raw_input("Choose from 1-3: ")) 中显示 EOF 错误。你能帮我么??谢谢

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" 
4

1 回答 1

2

你还没有完成你的程序:如果最后一条if语句什么都没有,所以 Python 解释器失败了。您必须至少输入一条指令来填充该块。如果你现在不想在这个块中做任何事情(例如在开发过程中,为了调试),你可以pass提出严格不做任何事情的语句。

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

编辑:我在您的代码中也看到了一些缩进问题,请小心并始终使用相同数量的空格来缩进块。

于 2013-12-27T14:18:39.413 回答