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

1. Please write the following code in python 3. Also, please anser all quetions

ID: 3756064 • Letter: 1

Question

1. Please write the following code in python 3. Also, please anser all quetions and share code.


Write a Python function `simulate_revenue(average, std_dev, months)`.
- it produces simulated revenue data according to a normal distribution with shape parameterized by `average` and `std_dev`, for a given number of months.
- It returns a list of length `months`.
- Round each item to the nearest cent. No fractions of a cent allowed.

Use `simulate_revenue` to generate two lists of random numbers which model potential revenue:

1. one list `before` with 24 months of revenue using the current mean and standard deviation,
2. another list `after` with 12 months of revenue using the predicted mean and standard deviation.

Then, concatenate `before` and `after` to produce a third list `all_months` containing the revenue of all 48 months.

---

Write a function `print_monthly_revenue(revenue, name)` that prints an arbitrary list to the screen, with these formatting requirements:
- round each number *when printing* to the nearest $100.
- do not modify the original list.
- prints a two-column output, with `month: revenue` (the month is implicitly given). Pad the month value so it is always of width 2.
- right-align the revenue value

Example:
`print_monthly_revenue(before, "before")` produces
```
Revenue for period 'before'

Mo: revenue
-----------
01: 123100
02: 98288
...
```

Call `print_monthly_revenue` on each of your concatenated list, and be sure to commit the output.

Explanation / Answer

1)

# importing Statistics module

import statistics

  

# creating a simple data - set

sample = [1, 2, 3, 4, 5]

  

# Prints standard deviation

# xbar is set to default value of 1

print("Standard Deviation of sample is % s "

                % (statistics.stdev(sample)))

# Python code to demonstrate stdev()  

# function on varioius range of datasets

  

# importing the statistics module

from statistics import stdev

  

# importing frations as parameter values

from fractions import Fraction as fr

  

# creating a varying range of sample sets

# numbers are spread apart but not very much

sample1 = (1, 2, 5, 4, 8, 9, 12)

  

# tuple of a set of negative integers

sample2 = (-2, -4, -3, -1, -5, -6)

  

# tuple of a set of positive and negative numbers

# data-points are spread apart considerably

sample3 = (-9, -1, -0, 2, 1, 3, 4, 19)

  

# tuple of a set of floating point values

sample4 = (1.23, 1.45, 2.1, 2.2, 1.9)

  

# Print the standard deviation of  

# following sample sets of observations

print("The Standard Deviation of Sample1 is % s"

                              %(stdev(sample1)))

                                

print("The Standard Deviation of Sample2 is % s"

                              %(stdev(sample2)))

                                

print("The Standard Deviation of Sample3 is % s"

                              %(stdev(sample3)))

                                

                                

print("The Standard Deviation of Sample4 is % s"

                              %(stdev(sample4)))

# Python code to demonstrate differnce

# in results of stdev() and variance()

  

# importing Statistics module

import statistics

  

# creating a simple data-set

sample = [1, 2, 3, 4, 5]

  

# Printing standard deviation

# xbar is set to default value of 1

print("Standard Deviation of the sample is % s "

                    %(statistics.stdev(sample)))

  

# variance is approximately the

# squared result of what stdev is

print("Variance of the sample is % s"

     %(statistics.variance(sample)))

2)

                              %(stdev(sample4)))