Category Archives: PYTHON

rigid body, cylinder

A spool of thread has rolled under the bed! Fortunately, you get the free end of the thread. The inner part of the reel where the thread is wound is a homogeneous, full cylinder of mass 3M and radius 2R. At each end there is a homogeneous cylindrical disc with mass M and radius 3R. The total mass of reels m = 5M. The moment of inertia of a homogeneous, full cylinder about its axis of symmetry is: I = 1 / 2mr ^ 2. The free end of the thread comes out from the underside of the inner cylinder, in the middle between the two outer discs. There is friction between the reel and the floor, with a static coefficient of friction = 0.25 and a dynamic coefficient of friction = 0.2.

1. Show that the maximum force at which the reel rolls without slipping is:
F <F_max = 5 / 3Mg

2. In which direction does the reel move as you pull with the force F = F_max? Do you get out of bed? Explain.

The next thing you do is to give the thread a strong bounce in the horizontal direction, that is, you use a large horizontal force F over a very short time interval t. The force is much greater than the frictional force, and you can therefore disregard the frictional force in that time interval while the string is working. After this time interval, when the force F has stopped working, the reel moves at speed v = v_o and angular velocity w_0.

3. How big is the impulse that the spool gets?

4. Show that the angular velocity w_0 is related to the linear velocity v_0 as follows:

w_o = w_0 ^ k = 2/3 (v_0 / R) ^ k

Python Grade Assignment

Your math teacher has asked you to write a program that grades the multiple-choice questions in a Math exam. The exam has 10 multiple-choice questions. Here are the correct answers:

1. A        6. B       

2.D          7.A       

3. B          8. B     

4.B          9.C       

5.C          10.D     

Your program should store the correct answers shown above in a list. It should ask the student to enter her answers for each of the 10 questions, and the answers should be stored in another list. After the students answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly at least answer 7 of the 10 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions. Your program must have at least the following functions:

getInput(inputList)
checkAnswers(userlist, correctAnswerList, rightQuestions, wrongQuestions)
*. The getInput function accepts a list and asks the user to input answers to the exam and stores them in the list. You must have an Input Validation loop: Only accept the letters A, B, C, D or a, b, c, d, as answers.

*. The checkAnswers function receives 4 parameters; the student’s answers the correct answers and an empty list for the student’s right answers and an empty list for the student’s wrong answers.

It compares the values in the correct answers list to the values of the student’s list. It updates the student’s right answers list and the student’s wrong answers list. it returns the number of correct answers to the main function.

sample run:

Enter the answers for each of the questions.
Question1:A
Question2:D
Question3:B
Question4:b
Question5:c
Question6:b
Question7:v
Enter only an A, B, C, D or a,b, c, d for each question.
Question7d
Question8:c
Question9:b
Question10:D
You have 3 answers wrong.

You have 7 answers right.
The wrong questions are: [7, 8, 9]
The right questions are: [1, 2, 3, 4, 5, 6, 10]

You passed the exam.

Foreign Exchange Option

We will use the Garman-Kohlhagan model (Links to an external site.) to price our options in this assignment. We will write a function that takes the option contract parameters (type–call or put, strike price, and expiration date) as well as market observations (spot exchange rate, volatility, and interest rates in both the domestic and foreign currencies) and returns the fair market value of the option contract.

The work will be decomposed into several functions and the pricing function will use these lower-level functions to calculate its result. The functions you will write are:

fx_option_price(call, strike, expiration, spot_date, spot, volatility, domestic_rate, foreign_rate)
fx_option_d2(term, volatility, d1)
fx_option_d1(strike, term, spot, volatility, domestic_rate, foreign_rate)
discount(rate, term)
years_apart(date1, date2)

python programming

The included Excel file lists HIV estimated prevalence of people ages from 15 to 49 in the world from 1979 to 2011. Use the dataset to complete following tasks:

Add one column as continent in the dataset and label each country/regionin the dataset to an appropriate continent such as Europe, Asia, Africa, North America, South America, Australia, or Antarctica. Explain how do you validate the correctness of your labelling. Output the updated dataset as a new CSV file. (1 point). (Note: You must write a Python program to complete the labelling, manully labelling wont get any credit).
Write a Python program to find the country/region in each continent thathas the highest average HIV estimated prevalence of people ages from 15 to 49 of from year 2000 to 2011. Find the country/region in each continent that has the lowest average HIV estimated prevalence of people ages from 15 to 49 of from year 2000 to 2011. Create a bar chart to show the highest average HIV estimated prevalence of people ages from 15 to 49 of from year 2000 to 2011 in each continent (1 point). Create a bar chart to show the lowest average HIV estimated prevalence of people ages from 15 to 49 of from year 2000 to 2011 in each continent (1 point). Create an overlaid bar chart to show the highest and lowest average HIV estimated prevalence of people ages from 15 to 49 of from year 2000 to 2011 in each continent (1 point). Select a country/region that is different from the average highest or lowest HIV estimated prevalence of people ages from 15 to 49 from year 2000 to 2011 from each continent, then create an overlaid line chart for the selected country/region, the average highest and lowest HIV estimated prevalence of people ages from 15 to 49 from year 2000 to 2011 for each continent (1 point).
Write a Python progrma to calculate the average HIV estimated prevalence of people ages from 15 to 49 for each year in the dataset for each continent (you only need simply add the estimate prevalence number of all countries/regions and divided by the number of the countries/regions in the continent). Based on the calculation, create a line chart for each continent to show the changes of the average HIV estimated prevalence from 1979 to 2011 (1 point). Create an overlaid line chart for all continents to show their changes of the average HIV estimated prevalence from1979 to 2011 (1 point).
Create two scatter plots to show the data (i.e. each country/region) inyear 1990 and year 2010, respectively. The vertical axis in the scatter plot is the HIV estimated prevalence, and the horizontal axis is the corresponding year average HIV estimated prevalence in each continent, which you calculated above. Using different color to show data from different continent (1 point). If you found any interesting result from the charts, explain it.
Write a report to explain how each question is implemented and its outputgraphs (2 point).