In: Computer Science
Use Python to solve, show all code
Write a program that sums a sequence of integers from a starting integer to and ending integer. The sequence is generated by skipping a value (e.g. 1,3,5,… or 2,6,10,14…). Prompt the user for a) a starting value greater than 0. Validate the value is greater than 0.
b) the ending value.
c) the value to skip
Print out the sum of the numbers for the sequence. If the starting value is 2, the ending value is 10 and the value to skip is 2, the sequence would be 2,4,6,8,10
Sample Interaction:
Enter the starting value: -1
Error – invalid number
Enter the starting value: 2
Enter the ending value: 10
Enter the value to skip: 2
The sum of the integers from 2 to 10 skipping 2 is 30
Python 3 code
============================================================================================
start=int(input('Enter the starting value: '))
while start<=0:
print('Error – invalid number')
start=int(input('Enter the starting value: '))
end=int(input('Enter the ending value: '))
skip=int(input('Enter the value to skip: '))
sum1=0
for i in range(start,end+1,skip):
sum1=sum1+i
print('The sum of the integers from ',start,' to ',end,' skipping
',skip, ' is ',sum1)
============================================================================================
output