40

I have a program that determines the number of points you get per day, for 5 days from an event.

source code:

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))

My question is how do I get it to make any number below or equal to zero a 0 without using decision statements (if's, case's, i think while or for loop is not allowed either)

cfi
  • 10,915
  • 8
  • 57
  • 103
user1686896
  • 483
  • 1
  • 5
  • 9

3 Answers3

169

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

max(0, points)
Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175
zeebonk
  • 4,864
  • 4
  • 21
  • 31
21
>>> f=lambda a: (abs(a)+a)/2         
>>> f(a)
0
>>> f(3)
3
>>> f(-3)
0
>>> f(0)
0
Marcus
  • 6,701
  • 4
  • 19
  • 28
4

Since I don't see boolean operators as a restriction, you can use:

points * (points>0)
yoavsnake
  • 131
  • 1
  • 5