python-3.x - 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
解决方案
if new_score < 0 and new_score > 200:
顺便说一句,这种情况永远不会发生:) 你应该重新考虑你的逻辑。
推荐阅读
- javascript - 在 Express 中编写一个发布请求以创建一个具有给定变量的列表
- c# - ADB2C - 令牌缓存过期时处理“在 AcquiretokenSilent API 中传递了 Null 用户”错误
- java - 从 SNMP4j 陷阱接收器获取目标 IP 地址
- vue.js - Vue:设置活动类 - 获取当前 DOM 元素
- c# - 使用 List<> 的 Convert.ChangeType 上的运行时异常
- c# - 从 SelectedItem DataGrid 中获取单元格或行对象
- .net - 使用 MSBuild 构建少数项目失败
- javascript - 只需要使用一次连接事件类型而不使用 cookie 或会话
- batch-file - 批量垂直拆分csv文件
- c# - 为什么要封装 ASMX 代理方法的参数?