首页 > 解决方案 > Newb python分数计数器语法问题

问题描述

我正在尝试用 Python 构建一个超级简单的分数计数器,这是我自学的语言。计数器应该只到 200 并且不超过。我被困在第二个循环中,并且在第二个条件“> 200”处的第 13 行出现无效的语法错误。

我还没有完成代码,因为我正在测试每个块。我可以就收到错误的原因获得帮助吗?此外,我确信这是乱七八糟的代码,但我刚刚学习了函数和参数以及条件,所以这是我目前所知道的。整个代码如下:

global score #creating starting score
score = 0 # set to 0
global high_score # highest score attainable
high_score = 200 # set to 200
global new_score # name to get current score 
new_score = score + int(input("score: ")) # how current score is reached
def total(): # function to find the complete score
    while score(): # loop for score at zero to add points
        if score is 0:
            print(new_score) #asks user for first score
            break
    while score(): # loop to keep adding numbers
        if new_score < 0 and > 200:
            print("next score: ", + score)
        break

标签: python-3.xsyntaxcounter

解决方案


if new_score < 0 and new_score > 200:

顺便说一句,这种情况永远不会发生:) 你应该重新考虑你的逻辑。


推荐阅读