Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please read all instructions carefully before submission. Failure to follow guidelines will result in loss of points. Ask for clarification if something is unclear. Purpose:

Please read all instructions carefully before submission. Failure to follow guidelines will result in loss
of points. Ask for clarification if something is unclear.
Purpose:
The primary purpose of this assignment is apply a for loop, a range, and a target variable to
generate a sequence of values. The secondary purpose of this assignment is to use a running total.
The algorithm in this assignment is similar to the ones we worked with in the Chapter 4 in-class
exercise #7 as revisited here:
Here is a script to add all the fractions 130,230,dots,3030 :
Modify the script so that it adds all the fractions 130,229,328,dots,301.
Solution:
sum =0.0
for i in range (1,31) :
sum +=i31-i
print('i =', i,'31- i =',31- i)
print('130+229+dots+301=, sum)
Requirements:
Write a Python program named fractions . py that:
asks the user for a positive integer n
finds the sum of the fractions from 11 to 1n.
finds the sum of the fractions from n1 to 1n.
Step 2 requires a loop to accumulate the values 11,12,13,dots,1n,
Step 3 requires a loop to accumulate the values n1,n-12,n-23,dots,1n,
For example, if the user input 6, the first sum would be:
11+12+13+14+15+16
The second sum would be:
61+52+43+34+25+16
Some sample runs of the program:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is a client?

Answered: 1 week ago