Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use python you are contacted by Dr. Matt Matic who teaches mathematics at Whatsa

ID: 3786867 • Letter: U

Question

Use python


you are contacted by Dr. Matt Matic who teaches mathematics at Whatsamatta U. He wants to be able consider the idea of summation.

Recall that a summation adds a sequence of numbers, and the result is the total. For example, if we were finding the summation of 5 starting at the value 1, we would find the total is 1+2+3+4+5=15.

Let's always assume that our starting value is 1.

He asks you to write a program that:

For example:

Please enter a positive number to sum: 0 Please enter a positive number to sum: -1 Please enter a positive number to sum: 6 sum of 1 is 1 sum of 2 is 3 sum of 3 is 6 sum of 4 is 10 sum of 5 is 15 sum of 6 is 21

Explanation / Answer

Do save your below code with .py extension.

# your code goes here

while(True):
    num = int(input('Please enter a positive num: '))
    if num <= 0:
        continue
    else:
        break
i = 0
res = 0
while(i<num):
  
   i = i + 1
   res = res + i
   print('Sum of ' + str(i) + ' is ' + str(res))

Input:

0
-1
6

Output:

Please enter a positive num: Please enter a positive num: Please enter a positive num: Sum of 1 is 1
Sum of 2 is 3
Sum of 3 is 6
Sum of 4 is 10
Sum of 5 is 15
Sum of 6 is 21

Link to the code:

http://ideone.com/j1wq8f

Hope it helps, do give your response.