在 Python 中编写石头剪刀布游戏时出错



我试图编写剪刀布石头布游戏的简单代码,这是完整的代码,但它在线路播放器中显示EOF错误= int(raw_input("从1-3中选择:"))。你能帮帮我吗??谢谢

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" 

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

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

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

最新更新