Why does sum() return incorrect value? /u/F1narion Python Education

I didn’t expect to be so frustrated with a basic function but here it is. Code is as follows:

”’ def get_sum(a,b): return sum(range(min(a,b),max(a,b))) ”’

The issue is, whenever a = 0 and b = 1, sum returns 0. Why does it return a zero? Is it stupid? The range is very obviously a (0, 1), so it should sum 0 and 1, resulting in 1. Yet, it says fuck you and returns 0. Adding 1 to max(a,b) solves it, but I genuinely just want to know why results of this function are so weird in this particular case. Any advice would be appreciated.

submitted by /u/F1narion
[link] [comments]

​r/learnpython I didn’t expect to be so frustrated with a basic function but here it is. Code is as follows: ”’ def get_sum(a,b): return sum(range(min(a,b),max(a,b))) ”’ The issue is, whenever a = 0 and b = 1, sum returns 0. Why does it return a zero? Is it stupid? The range is very obviously a (0, 1), so it should sum 0 and 1, resulting in 1. Yet, it says fuck you and returns 0. Adding 1 to max(a,b) solves it, but I genuinely just want to know why results of this function are so weird in this particular case. Any advice would be appreciated. submitted by /u/F1narion [link] [comments] 

I didn’t expect to be so frustrated with a basic function but here it is. Code is as follows:

”’ def get_sum(a,b): return sum(range(min(a,b),max(a,b))) ”’

The issue is, whenever a = 0 and b = 1, sum returns 0. Why does it return a zero? Is it stupid? The range is very obviously a (0, 1), so it should sum 0 and 1, resulting in 1. Yet, it says fuck you and returns 0. Adding 1 to max(a,b) solves it, but I genuinely just want to know why results of this function are so weird in this particular case. Any advice would be appreciated.

submitted by /u/F1narion
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *