gpt4 book ai didi

algorithm - 如何在不使用决策结构的情况下在 python 中将负数更改为零

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:19:09 26 4
gpt4 key购买 nike

我有一个程序可以确定您在某项事件后的 5 天内每天获得的积分数。

源代码:

total=0

for x in range (5):
points=int(input('How many points did you get today?'))
total=total+points

print ('You got {0} points this event'.format(total))

我的问题是如何在不使用决策语句的情况下使任何小于或等于零的数字变为 0(if's,case's,我认为 while 或 for 循环也是不允许的)

最佳答案

你能使用内置函数吗?因为这通常是使用:

max(0, points)

关于algorithm - 如何在不使用决策结构的情况下在 python 中将负数更改为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12518760/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com