# I Really Need Help With This Python Programming Assignment Program Requirements

I really need help with this python programming assignment

Program Requirements

For part 1, I need a program with 2 functions specifically these

• fib(): Takes a single integer argument num terms greater than or equal to 1 and for each

of the num terms terms of the Fibonacci sequence prints 1) the number of the term—i.e., 1,

2, 3…, 2) the corresponding Fibonacci number, and 3) the ratio of the current and previous Fibonacci

numbers as shown below. The ratio, printed only for x1 and higher, is an approximation

of the golden ratio = 1.61803398875…

• main(): Prompts the user for the number of terms s/he wants to find and calls the void function

fib().

The program giving the following output

1 Enter the number of terms you want to find: 2

2 1 1

3 2 1 1.0

1 Enter the number of terms you want to find: 9

2 1 1

3 2 1 1.0

4 3 2 2.0

5 4 3 1.5

6 5 5 1.66666666667

7 6 8 1.6

8 7 13 1.625

9 8 21 1.61538461538

10 9 34 1.61904761905

The last line of your program should be a call to main(). Don’t forget to include docstrings!

How many terms are needed to obtain an approximation to the golden ratio accurate to 4 decimal

places?

Program Requirements

For part 2,i need the following functions

• get floats(): It take a single integer argument and returns

a list of floats. where it was something like this

def get_floats(n):

lst = []

for i in range(1,n+1):

val = float(input(‘Enter float ‘+str(i)+’: ‘))

lst.append(val)

return lst

• summer(): This non-void function takes a single list argument, and returns the sum of the

list. However, it does not use the sum() function to do so. See “Summing Values the Hard

Way” below for instructions on how to implement this function.

• average(): This non-void function uses the list of numbers returned by get floats() as

its argument and returns the average value, a float, to the calling program. It calls summer()

to sum the values in the list. Its body can actually be a single line: a return statement followed

by the appropriate expression. See the notes below on “Calculating Averages.”

• std dev(): This non-void function takes two arguments, the list of numbers obtained by

get floats() and the average obtained using average(), and returns the standard deviation,

a float value. The function should initialize an accumulator to zero and then use a

for-loop in which the average is subtracted from the list value and the result is squared and

added to the accumulator. After the for-loop has finished looping, the accumulator should be

divided by the number of elements in the list, the square root taken, and the result returned to

the calling function. See the notes below on “Calculating Standard Deviations.”

• main(): Finally, write the void function main(). It should prompt a user for the number

of elements desired in the list and should call the non-void functions get floats(),

average(), and std dev(). Then it should print the average and standard deviation to the

screen. Use the round() function to round off the standard deviation to two decimal places.

Summing Values the HardWay1

summer() takes a single list argument. First you need to initialize an accumulator to zero, then

use a for-loop to add the value of each element in the list, and finally return the total sum to the

calling program. The proper behavior of summer() is demonstrated below.

1The easy way is to use the built-in function sum().

5

1 >>> x = [9, 3, 21, 15]

2 >>> summer(x)

3 48

4 >>> summer([31.12, -16.32, 24.9, 82.0, 14.0])

5 135.7

Calculating Averages

Recall that the average of a list of numbers is simply the sum of the values divided by the number of

values. Mathematically, for a set of numbers x1, x2, · · ·, xN, the average is given by

¯x =

1

N

(x1 + x2 + · · · + xN)

where N is the number of terms in the list. The average, or mean, is often indicated by an overbar—

i.e., ¯x indicates the average of a set of numbers xk. The average is also given by

¯x =

1

N

XN

k=1

xk

where the uppercase Greek letter Sigma () means perform a sum. The expression to the right of

Sigma is what is to be summed. The expression below Sigma initializes a summation index (in this

case k) and the term above Sigma indicates the final value of the summation index.

Calculating Standard Deviations

The standard deviation is a measure of how much fluctuation or deviation there is in a set of numbers

after the average has been subtracted from each of the values2. If all the values in a list are equal to

the average, then the standard deviation is zero. If the standard deviation is large, then it means many

values deviate considerably from the average. The standard deviation is represented by the lowercase

Greek letter sigma (). For a set of numbers x1, x2, · · ·, xN, the standard deviation is given by

=

s

1

N

[(x1 − ¯x)2 + (x2 − ¯x)2 + · · · + (xN − ¯x)2]

where ¯x is the average. Recall that in Python we can square a value z using z ** 2 and we can

calculate the square root using z ** 0.5.

The following three examples demonstrate the results you should obtain for three different sets of

input for your stats.py program. Each of these has the same mean but an increasing standard

deviation. In the first, all the values are the same and hence the standard deviation is zero.

1 Enter the number of list elements: 5

2 Enter float 1: 50

2For further discussion of standard deviation, see .

6

3 Enter float 2: 50

4 Enter float 3: 50

5 Enter float 4: 50

6 Enter float 5: 50

7 Average = 50.0

8 Standard deviation = 0.0

Here the values are spread out, spanning the range 30 to 70:

1 Enter the number of list elements: 5

2 Enter float 1: 30

3 Enter float 2: 40

4 Enter float 3: 50

5 Enter float 4: 60

6 Enter float 5: 70

7 Average = 50.0

8 Standard deviation = 14.14

In the final example the values range between 10 and 90:

1 Enter the number of list elements: 5

2 Enter float 1: 10

3 Enter float 2: 30

4 Enter float 3: 50

5 Enter float 4: 70

6 Enter float 5: 90

7 Average = 50.0

8 Standard deviation = 28.28

Don’t forget to include docstrings in all your functions!