Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a negative number to zero in python without using decision structures

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)

like image 677
user1686896 Avatar asked Sep 20 '12 18:09

user1686896


People also ask

How do you convert a negative number in Python?

In Python, positive numbers can be changed to negative numbers with the help of the in-built method provided in the Python library called abs (). When abs () is used, it converts negative numbers to positive. However, when -abs () is used, then a positive number can be changed to a negative number.

How do I remove negative values in Python?

A common math method is abs. This computes absolute values. It removes the negative sign (if there is one) from the number and returns that.


1 Answers

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

max(0, points) 
like image 86
zeebonk Avatar answered Sep 18 '22 15:09

zeebonk