1. Engineering
  2. Computer Science
  3. python could you help me understand the math behind this...

Question: python could you help me understand the math behind this...

Question details

Python:

Could you help me understand the math behind this range function? I don’t understand how they arrive at these answers.

Given the output of 10,what output is produced by line 2? (Answer: 12)

Given the output of 11, what output is produced by line 3? (Answer: 8)

Code:

the_max=int(input("Enter the upper limit: "))

the_sum = 0

extra = 0

for number in range(1, the_max):

    if number%2 and not number%3:

        the_sum=the_sum+number

    else:

        extra=extra+1

print(the_sum) #Line 2

print(extra) #Line3

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution