努力的小bai 2018-10-12 10:59 采纳率: 0%
浏览 825
已采纳

简单的python程序报错,改了半天也不知道哪里错了,请解答 谢谢

play = input("请输入剪刀(0)石头(1)布(2):")

player = int(play)

com = 1

if (player==0 and com==2) or (player==1 and com==0) or (player==2 and com==1):
        print("你赢了,真厉害")
elif player==com:
        print("平局,再来一次")
else (player==0 and com==1) or (player==1 and com==2) or (player==2 and com==0):
        print("你输了,不要走,决战到天亮")

报错信息如下: File "jsb.py", line 9
else (player==0 and com==1) or (player==1 and com==2) or (player==2 and co
^
m==0):

SyntaxError: invalid syntax

网上查询说是因为括号、冒号什么的,我都用英文输入法重新打了一次还是错误,希望大家解答,初学者请大家多多理解,谢谢!

  • 写回答

4条回答 默认 最新

  • 高山听流水 2018-10-12 11:48
    关注

    代码应该改成这样
    play = input("请输入剪刀(0)石头(1)布(2):")

    player = int(play)

    com = 1

    if (player==0 and com==2) or (player==1 and com==0) or (player==2 and com==1):
    print("你赢了,真厉害")
    elif player==com:
    print("平局,再来一次")
    elif (player==0 and com==1) or (player==1 and com==2) or (player==2 and com==0):
    print("你输了,不要走,决战到天亮")

    注意:python else后面不能接判断条件,if和elif后面才可以加

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料