Question

In: Computer Science

Use Python to solve, show all code Write a program that sums a sequence of integers...

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

Solutions

Expert Solution

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


Related Solutions

Use Python to solve: show all code: 2) For the last assignment you had to write...
Use Python to solve: show all code: 2) For the last assignment you had to write a program that calculated and displayed the end of year balances in a savings account if $1,000 is put in the account at 6% interest for five years. The program output looked like this: Balance after year 1 is $ 1060.0 Balance after year 2 is $ 1123.6 Balance after year 3 is $ 1191.02 Balance after year 4 is $ 1262.48 Balance after...
Use Python to solve: show all work 1) Write a program that prints out a deck...
Use Python to solve: show all work 1) Write a program that prints out a deck of cards, in the format specified below. (That is, the following should be the output of your code). 2 of hearts 2 of diamonds 2 of spades 2 of clubs 3 of hearts 3 of diamonds 3 of spades 3 of clubs 4 of hearts 4 of diamonds 4 of spades 4 of clubs Continue with 5,6,7.. ending with A of hearts A of...
every code should be in java Program 1: Write a while loop that sums the integers...
every code should be in java Program 1: Write a while loop that sums the integers from 1 to 10, excluding 3 and 6. Print the sum. [Hint: Use logical operators] Program 2: Write a for loop that attempts to display the numbers from 1 to 10, but terminates when the control variable reaches the value 6. Program 3: Write a do...while loop that prints the integers from 10 to 0, inclusive.
Answer question in Python, show all code: Write a program that calculates and displays the end...
Answer question in Python, show all code: Write a program that calculates and displays the end of year balances in a savings account if $1,000 is put in the account at 6% interest for five years. For this problem, assume interest is calculated annually. (That is, if I put $1000 in a bank account at the beginning of the year, then the balance at the end of the year is $1,000 + $1,000*6%.) You may assume no money is removed...
Do not use arrays and code a program that reads a sequence of positive integers from...
Do not use arrays and code a program that reads a sequence of positive integers from the keyboard and finds the largest and the smallest of them along with their number of occurrences. The user enters zero to terminate the input. If the user enters a negative number, the program displays an error and continues. Sample 1: Enter numbers: 3 2 6 2 2 6 6 6 5 6 0 Largest Occurrences Smallest Occurrences 6 5 2 3. Do not...
One Problem/Question (Four Parts) Write a python program which prints a sequence of integers that are...
One Problem/Question (Four Parts) Write a python program which prints a sequence of integers that are multiples of 10, starting at 0 and ending at 100. Write a python program that computes the average of 10 random odd integers, ranging from 0 to 500. Write a python program that prints whatever the user enters, and stops when the user types “done”, using an infinite loop and a break statement. Same as number three but use a condition. The loop terminates...
User Python to solve; show all code: A user will enter in data for a basketball...
User Python to solve; show all code: A user will enter in data for a basketball team. For each player on the team the user will enter The player’s last name The average number of point the player scored last season The number of games the player is projected to play in this year Write a program that will prompt the user for the player data described above. The user does not know how many players are on the team...
Answer question in Python, show all code 2) Recall the palindrome problem. Write a new program...
Answer question in Python, show all code 2) Recall the palindrome problem. Write a new program that prompts the user for a string and checks to see if that string is a palindrome. For this updated program, input strings may have punctuation marks, spaces, and capitalizations, but these are ignored in the palindrome check. Here are some sample interactions. Please enter a string to check: A man, a plan, a canal: Panama! The string "A man, a plan, a canal:...
Program must be in Python Write a program in Python whose inputs are three integers, and...
Program must be in Python Write a program in Python whose inputs are three integers, and whose output is the smallest of the three values. Input is 7 15 3
PLEASE WRITE IN PYTHON A sequence of integers is said to be Fibonacci-like if each element...
PLEASE WRITE IN PYTHON A sequence of integers is said to be Fibonacci-like if each element of the sequence (except the first two elements) is the sum of the previous two integers in the sequence. For example, the sequence 10, 14, 24, 38, 62, 100, 162, 262 is Fibonacci-like. Note that the first two integers in the above sequence are arbitrary. Each of the remaining integers is the sum of the two integers just before it in the sequence. For...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT