猿问

TypeError:调用 print 时,'str' 对象不可调用

每当我运行它时,它会在 25% 到 50% 的时间里工作,我不知道为什么。以前我在使用 if 语句时遇到了麻烦,但这是一个我忘记的简单解决方法,但这让我感到困惑,因为它确实有效......有时。顺便说一句,这段代码是在 repl.it 上制作和运行的。编辑:我在最后添加了一个打印变量 rng 的部分,它说 typeError:'str' pbject is not callable


import random

rng=(random.randint(1,3))

player=input("rock, paper, or scissors ")

if player=="rock":

  if rng==1:

    print("paper covers your rock")

  elif rng==2:

    print=("both rock, tie")

  elif rng==3:

    print("your rock crushes scissors")

  else:

    print("error")

elif player=="paper":

  if rng==1:

    print("both paper, tie")

  elif rng==2:

    print=("your paper covers rock")

  elif rng==3:

    print("scisors cut your paper")

  else:

    print("error")

elif player=="scissors":

  if rng==1:

    print("your scissors cut paper")

  elif rng==2:

    print=("rock crushes your scissors")

  elif rng==3:

    print("both scissors, tie")

  else:

    print("error")

else:

  print("error")


炎炎设计
浏览 87回答 1
1回答

杨魅力

在这条线上:print=("rock crushes your scissors")覆盖的=值print,将其转换为字符串而不是函数。这会导致您的打印语句不打印!所以,只需删除=标志。正如@chitown88 所指出的那样,这个错字实际上在您的代码中出现了三次。
随时随地看视频慕课网APP

相关分类

Python
我要回答