Category: 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.

Beginner’s Python

Part 1:

Write code that writes the names of three of your favorite movies to a file named movies.txt.

Each movie should be on a separate line in the text file.

Use file explorer to manually open the text file in a text editor (like Notepad, Notepad++, etc.) to verify your Python code wrote three movie names, one per line.
Sample output to a file:

The Matrix
Gladiator
Top Gun

Part 2:

Write a program that asks the user for the name of a file.

The program should display only the first five lines of the files contents if the file contains five or more lines.

If the file contains less than five lines, it should display the files entire contents.

Sample input/output (5 or more lines in the file):
Enter the name of the file: pokemon.txt

Bulbasaur
Ivysaur
Venusaur
Charmander
Charmeleon

Sample input/output (less than 5 lines in the file):
Enter the name of the file: pokemon.txt

Bulbasaur
Ivysaur
Venusaur

Part 3:
Use the movies.txt file you created in Lab 12.

Write code that opens the movies.txt file and appends three new movies to the end of the file. The three new movies must not overwrite the existing three movies already in your file.

Use file explorer to manually open the text file in a text editor (like Notepad, Notepad++, etc.) to verify six movie names were written, one per line.
Sample output to a file:

The Matrix
Gladiator
Top Gun
Shawshank Redemption
Second Hand Lions
Back to the Future

Part 4:

Download the scores.txt file. (https://elearn.volstate.edu/content/enforced/8012611-16023.202010/scores.txt?_&d2lSessionVal=mxCQ12wFgLrnN0ayxsA6n2leF) It contains a series of names and scores (an integer between 1 and 100).

Place the scores.txt file in the same folder as your assignment 13 Python file.

Open scores.txt and review the format and layout of the file.

Write a program that reads scores.txt and displays the name of the student with highest score and the actual score (see output below).

Also print the the number of records in the file.

TIP #1: You can use an if statement to keep track of the highest score found (and the name of the student the score belongs to) as you read through the records, and a variable to keep count of the number of records.

TIP #2: If you’re not sure where to begin, read section 6.3, “Processing Records”.

Sample output:
Highest Score: Michael, 97
Number of records: 12

Part 5:

Perform the following steps in the file you created above (lastname_firstname_lab14.py):

Write a function called is_valid_email(email_address) that validates an email address.

The email address to validate is: your.name@volstate.edu
Iterate over the string looking for the @ character.

Verify the string ends with: .edu

If both the @ character and .edu is found, then the email address is valid.

The function should return true if the email is valid. The function should return false if the email is invalid.
Call the is_valid_email function from your main code and print the result (true or false) returned by the function.

Sample output (for a valid email address):

true
Sample output (for an invalid email address):

false

Part 6:

Write a program that accepts a sentence as input and converts each word to Pig Latin.

In this version of Pig Latin: to convert a word to Pig Latin, you remove the first letter and place that letter at the end of the word. Then, you append the string ay to the word. See below for example input and output.

Make a function called english_to_piglatin(input), where the function accepts a string (entered by the user in #1 above) of what to convert to Pig Latin.

Call the english_to_piglatin function from your main code.

Optional Challenge: Create the reverse function: piglatin_to_english. This function coverts Pig Latin back to English.
TIP for #5: Suppose a sample string is named “word” and its value is set to “something”. word[0] slices the “s”.  word[9] slices the “g”. word [7:9] slices”ng”. You can see how this is helpful for reversing Pig Latin. However, since the string could be any number of characters, you cannot hard-code 7 and 9. You must use the string length as a relative basis.

Sample input/output:
English input: I SLEPT MOST OF THE NIGHT
Pig Latin output: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY

Sample input/output (from Optional Challenge #5)
English input: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY
Pig Latin output: I SLEPT MOST OF THE NIGHT

NY Taxi Notebook Assignment

Download and unzip the NYC taxi dataset from Cyrille Rossant on GitHub: https://github.com/ipython-books/minibook-2nd-data (Links to an external site.)
Open the notebook file attached below.  You will be adding your code (make sure you add headers and comments) to the existing code, and make sure your code is well organized.
Please upload the data and display data columns, number of rows, variable types, and numeric statistics + categorical variable frequencies.
Display a scatter plot of pick up locations.  For which vendor is it easiest to find a cab?
Display a histogram of trip distances. What is the most common trip distance?
Display a histogram of the fare total amounts. What can you say about the data?
How many unusually long trips (of greater than 100 miles) do you see?

Beginner’s Python

Part 1:
Write a program that asks the user for a secret number between one and ten. This will become the number that the player tries to “guess”.

Ask the user player to guess a number between 1 and 10.

If the user’s guess is higher than the secret number, the program should display “Too high. Try again.”

If the user’s guess is lower than the random number, the program should display “Too low. Try again.”

The program should use a loop that repeats until the user correctly guesses the secret number.

Then the program should display “You Win!”

TIP: Use a while loop

Sample input/output:
Enter the secret number: 7

Guess a number between 1 and 10: 3
Too low. Try again.

Guess a number between 1 and 10: 9
Too high. Try again.

Guess a number between 1 and 10: 7
You Win!

Part 2:
Write a program that converts the common measurements below. Use functions to logically organize each conversion task below. Each of the conversion functions should return the result. The conversion functions should not print the result.

Convert feet to inches. (1 foot = 12 inches)

Convert yards to feet. (1 yards = 3 foot)

Convert miles to yards. (1 mile = 1760 yards)

Convert miles to feet. (1 mile = 5280 feet)

Print the output of the conversion to the screen.

Display a menu that asks the user to select from the above options and with the option to exit the program.

After the user selects a menu option and the output is printed, ask the user for another menu option. This process repeats until the user selects 5 to exit.
Sample input/output:
Conversion Menu:

1. Convert feet to inches
2. Convert yards to feet
3. Convert miles to yards
4. Convert miles to feet
5. Exit

Please choose a menu option: 1
Enter the number of feet: 3

There are 36 inches in 3 feet.

Please choose a menu option: 5
Goodbye.

Part 3
Create a list of something that you choose, such as a list of scores, colors, movies, general numbers, etc. Call the list you create: my_list

Iterate over the list, printing each item in the list.

Add a new item to the list.

Print the length of the list.

Delete an item from the list.

Print the length of the list again.

Sample output (the output is shown below but not all coding steps above have output):

red
blue
green

3
2

Part 4:
You have a list called: numbers = [74, 19, 105, 20, -2, 67, 77, 124, -45, 38]
Design a program that uses a loop to build another list named valid_numbers .

This valid_numbers list will contain some of the numbers from the numbers list shown above. If a number in the numbers list is between 0 and 100, you will add that number to the valid_numbers list.

Is the first number in the numbers list between 0 and 100? If so, add it to the valid_numbers list.
Is the second number in the numbers list between 0 and 100? If so, add it to the valid numbers list.
Keep going. The numbers list could be of any size and contain any number, so don’t assume a certain list content or length.
The program should then print the valid_numbers list.

The program should also print the total and average of the values in the valid_numbers list.

TIP: Average is the sum divided by the number of items. Iterate over the valid_numbers, sum all the numbers, and calculate the average.
TIP: You are not expected to research Python topics we haven’t discussed in class. Just use what we’ve learned in class.

You MUST use a loop. You MUST use a list. You MUST follow the directions above.
Sample output:
[74, 19, 20, 67, 77, 38]
Total: 295
Average: 49.167

Python Assignment for Physics

Python code using Physics and mathematical concepts.
Need seperate answer for each question in Python code. Please also make some note throughout the code using the # to keep track of what is being coded.
Please submit answer in a way where the code can be copy pasted.
When the question states Markdown, please use markdown cells. The first question 1a for example, only asks to use Markdown and Latex to display an matrix equation, no codes are required for this specific question.

Python

Create a class called Tour.  An instance of this class is to be instantiated with two US cities, and is used to fetch information from the web.  Specifically, the class must define:

1.    __init__  The constructor takes two strings as arguments, each giving a city name and state abbreviation, indicating the origin and destination.  For example: Tour(New York, NY, Los Angeles, CA)represents a tour that starts in New York city and ends in Los Angeles.
2.    distance  This method takes a single (optional) argument indicating a mode one of the strings driving (default), biking, or walking.  It returns the total distance (in meters) covered by the tour for the indicated mode.  This method is where you will use urllib functions to get data from the web to find the distances between two locations in the tour and calculate the total distance.  If a response does not contain a distance value, the method should raise a ValueError exception.

Graphical User Interface Description:
Create a class called TourGui. An instance of this class is to be instantiated in the main. Specifically the class must define:
1.    __init__ The constructor doesnt take any arguments. The constructor creates two frames in the window, a top frame and buttom frame. The top frame contains a  label and an entry widget for the following fields: origin, destination, and mode. The bottom frame contains a label and text widget for Distance and a button widget for Get Distnace. The GUI should like the following:

2.    onClick This method is the event handler for the Get Distance Button. When the button is clicked, the origin, destination and mode fields are read, the query is made and the distance between the origin and the destination is displayed. If the user enters an invalid mode, a message box shows up indicating invalid mode was entered:

If the distance was not found between the origin and the destination, a message box shows up indicating the distance was not found:

Deliverables
Create a zipfile of the project folder and submit on Canvas. You must name your project as FirstnameLastnameFinalProject.

Create the game Columns using Python

This project is focused on implementing the mechanics of Columns, along with a program that you can run in the Python shell with a very spartan user interface that you’ll use to test it.
There are features that must be completed.

Assignment Instructions found here:
https://www.ics.uci.edu/~thornton/ics32/ProjectGuide/Project4/

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).