【问题标题】:How to fix score addition failure如何修复分数加法失败
【发布时间】:2019-06-14 20:30:54
【问题描述】:

我正在做一个测验。用户有 3 次尝试猜测问题的答案。

我的问题是评分系统无法正常工作。如果用户第一次猜到答案,它会增加 3 分,这是有效的。但是,如果用户第二次猜到应该加 1 分,程序就会加 0 分。

我尝试过询问周围的人并交换 if 语句,这样就失去了程序假设分数的可能性。

songnameguess = input("Guess the name of the song!")
counter = counter + 1
while counter < 3 and songnameguess != randomsong :
        songnameguess = input("Nope! Try again!")
        counter = counter + 1
if songnameguess == randomsong:
    print ("Well done!")
    answer = input("Do you want to continue playing?")
    print (counter)
    if counter == 2:
        score == score + 1
        print (score)
    elif counter == 1:
        score = score + 3
        print (score)

当用户第一次猜对答案时,他们的分数应该加 3 分,当用户第二次猜对答案时,他们应该在他们的分数上加 1 分。如果用户在三次尝试中都没有猜到分数,则游戏结束。

【问题讨论】:

  • 应该是score = score + 1,您在其中输入了两个=?
  • == 是比较,= 是赋值。

标签: python


【解决方案1】:

这行代码错了

    score == score + 1

== 不应使用,但应使用 =

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 2019-05-30
    相关资源
    最近更新 更多