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

(NEEDS TO BE IN PYTHON 2.7) Part 1 Write a loop that sums all positive integers

ID: 3806969 • Letter: #

Question

(NEEDS TO BE IN PYTHON 2.7)

Part 1

Write a loop that sums all positive integers from 1 to 100

Note: The answer is 5150

Print out the result in sentence form such as:

The sum of all positive integers from 1 to 100 is 5150

Part 2

Make your loop interactive by allowing the user to choose the starting value and the ending value

Print out the results in sentence form

Hw7-Summing with a loop Part 1 Write a loop that sums all positive integers from 1 to 100 Note: The answer is 5150 Print out the result in sentence form such as: The sum of all positive integers from 1 to 100 is 5150 Part 2 Make your loop interactive by allowing the user to choose the starting value and the ending value Print out the results in sentence form

Explanation / Answer

#python code

#part 1
sum = 0
i = 1
while i <= 100:
   sum = sum + i
   i =i + 1
print "Sum of all positive numbers from 1 to 100 is ",sum
#output: Sum of all positive numbers from 1 to 100 is 5050


#part 2
startingValue = int(raw_input("Enter the starting value: "))
endingValue = int(raw_input("Enter the ending value: "))

sum = 0
while startingValue <= endingValue:
   sum = sum + startingValue
   startingValue = startingValue + 1
print "Sum of all positive numberss form",startingValue,"to",endingValue,"is",sum

'''
output:

Enter the starting value: 23
Enter the ending value: 56
Sum of all positive numberss form 57 to 56 is 1343

'''