34

イベントから 5 日間、1 日あたりに獲得できるポイント数を決定するプログラムがあります。

ソースコード:

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、case、while または for ループも許可されていないと思います)。

4

2 に答える 2

140

Can you use built-in functions? Because this is normally done using:

max(0, points)
于 2012-09-20T18:40:46.003 に答える
18
>>> f=lambda a: (abs(a)+a)/2         
>>> f(a)
0
>>> f(3)
3
>>> f(-3)
0
>>> f(0)
0
于 2012-09-21T08:09:29.177 に答える