Answer the following problems in Python
for
loop, sum integers from 1 to 100 and break
if your sum is greater than 200. Print the integer which causes your sum to exceed 200.while
loop, a break statement, and your function from the previous question. You must use python tutor on this problem to receive full creditWrite what quantity the question asks for symbolically, write the equation you need to compute symbolically (if necessary) and compute your answer in Python.
You accidentally open youtube while doing your homework. After watching one video, you find another interesting video you must watch with probability 25%. Define the sample space and define success to reflect a geometric distribution.
What's the probability that you will return after watching exactly one video?
What's the probability that you will return after watching exactly two videos?
Your friend wants to know when you will get back to homework. You explain the sample space is unbounded, but you guarantee there is a 99% chance you will return to your homework after how many videos? You must use python tutor on your loop to receive full credit.
What is the expected number of videos you will watch? You may use any method to compute this.
The per-capita (expected) income in the US is \$27,500 and its standard deviation is \$15,000. Assuming the normal distribution, answer the following questions. You may use scipy stats for all of these but you must use Z values.
We're going to write a program to discover how much to save in our retirement accounts. You are going to start with $P$ dollars, your principal. You invest in low-cost index funds which have an expected return of 5% (your principal is 105% of last years value). To live after your retirement, you withdraw \$30,000 per year. Complete the following tasks:
Write a function which takes in a principal, $P$, maturation rate of $r$, and withdrawl amount of $W$. It returns the amount of money remaining. Withdrawl occurs before maturation. Using your function, with a principal of \$250,000 and the numbers given above, how much money remains after 1 year? Call this function annual.
Write a new function called terminator which takes in $P$, $r$ and $W$. It should use your annual function and a for loop. It returns the number of years before your principal is gone and you have no more retirement money. Since you're using a for loop, you should have some upper bound. Let's use 50 for that upper bound. To test your method, you should get 11 years using the numbers from part 1.
Make a graph of principal vs number of years. You should use a for loop, not numpy, since your functions aren't built for numpy arrays. Your principals should run from \$100,000 to \$500,000.
Make your terminator (for this part only) have an upper bonud for 1000 years. You are a vampire. Make a plot from \$100,000 to \$750,000. How much money do you need in retirement as a vampire?
Rewrite your annual function to sample random numbers. Youur investment rate of return (maturation rate) should be sampled from a normal distribution with standard deviation 0.03 and mean 0.05. Your withdrawl should come from a normal distribution with mean \$30,000 and standard deviation \$10,000. Call your new annual, s_annual and your new terminator s_terminator. Answer the following questions:
Previously you calculated you can live for 11 years off of a principal of \$250,000. Using your new terminator and annual functions, make a histogram for how many years you can live off of \$250,000. Use 1000 samples.
Create a function which takes in a principal and a target number of years for the principal to last. It should return what fraction of terminator runs succeed in lasting that many years. For example, a principal of \$250,000 should have about 55%-60% success with 10 years.
Using any method you would like (e.g., trial and error or plotting), what should your principal be to ensure retirement for 25 years in 95% of the samples?
In [ ]: