Question

In: Computer Science

Suppose you have ridden a bicycle from New York City to Key West, Florida. Your bicycle...

Suppose you have ridden a bicycle from New York City to Key West, Florida. Your bicycle odometer shows the total miles you have travelled thus far, which you make a note of each day with paper and pencil. Your first two entries might be ‘55’ and ‘120’, indicating that you rode your bike 55 miles on day 1 and 65 miles on day 2. Your task is to create a NumPy array wherein you can record the cumulative miles you recorded each day during your trip “by hand”. Then use your Python skills to show the total miles that you rode each day. Assume the trip took a total of 35 days and included at least 4 non-consecutive days where no cycling was possible due to either weather conditions or personal fatigue/soreness. For the remaining 31 days, you would have covered the entire distance between NYC and Key West. Complete your work within your Jupyter Notebook for this assignment and be sure to include a writeup explaining your approach to this problem, including the ways in which you decided to make use of NumPy.

Solutions

Expert Solution

First the cumulative distance is recorded into the program by asking the user to enter the details. Numpy's 1D array is used to store the cumulative values when the user enters it. These values are then convereted into everyday distance by subtracting each element with its previous element. Then the array is traversed and the daily distance is printed.

Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.

Below is the output of the program:


Below is the code to copy:
#CODE STARTS HERE----------------
import numpy as np

# # Following numpy array contains 34 days values(for testing)
# miles = np.array([55,120,180,180,265,320,350,456,566,566
#           ,623,698,742,780,802,845,899,964,1022,1100,
#             1120,1180,1180,1206,1287,1331,1371,1405,1455,1500,
#             1546,1587,1600,1611])

miles = np.array([])
for x in range(34):
   inp = int(input("Enter reading for day "+str(x+1)+": "))
   miles = np.append(miles,inp)

#Convert cumulative array to non cumulative numpy array
miles[1:] -= miles[:-1].copy()
for mile in range(len(miles)): #loop through the array
   print("Day "+str(mile+1)+": ",miles[mile],"miles") #Display miles for everyday
#CODE ENDS HERE------------------

Related Solutions

You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1,220,000. Over the past five years, the price of land in the area has increased 4 percent per year, with an annual standard deviation of 33 percent. A buyer has recently approached you and wants an option to buy the land in the next 12 months for $1,370,000. The risk-free rate of interest is 4 percent per year, compounded continuously. How much...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1.8 million. Over the past five years, the price of land in the area has increased 11 percent per year, with an annual standard deviation of 24 percent. A buyer has recently approached you about buying the land in the next 11 months for $2,030,000. The risk-free rate of interest is 5 percent per year, compounded continuously. You want the option to...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1,270,000. Over the past five years, the price of land in the area has increased 7 percent per year, with an annual standard deviation of 33 percent. A buyer has recently approached you and wants an option to buy the land in the next 12 months for $1,420,000. The risk-free rate of interest is 5 percent per year, compounded continuously. How much...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1,320,000. Over the past five years, the price of land in the area has increased 6 percent per year, with an annual standard deviation of 32 percent. You have approached a buyer and would like the option to sell the land in 12 months for $1,470,000. The risk-free rate of interest is 4 percent per year, compounded continuously.    What is the...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1,340,000. Over the past five years, the price of land in the area has increased 8 percent per year, with an annual standard deviation of 31 percent. You have approached a buyer and would like the option to sell the land in 12 months for $1,490,000. The risk-free rate of interest is 4 percent per year, compounded continuously.    What is the...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1,320,000. Over the past five years, the price of land in the area has increased 6 percent per year, with an annual standard deviation of 32 percent. A buyer has recently approached you and wants an option to buy the land in the next 12 months for $1,470,000. The risk-free rate of interest is 4 percent per year, compounded continuously. How much...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1,280,000. Over the past five years, the price of land in the area has increased 6 percent per year, with an annual standard deviation of 35 percent. A buyer has recently approached you and wants an option to buy the land in the next 12 months for $1,430,000. The risk-free rate of interest is 4 percent per year, compounded continuously. How much...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1,230,000. Over the past five years, the price of land in the area has increased 5 percent per year, with an annual standard deviation of 34 percent. A buyer has recently approached you and wants an option to buy the land in the next 12 months for $1,380,000. The risk-free rate of interest is 5 percent per year, compounded continuously. How much...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently...
You own a lot in Key West, Florida, that is currently unused. Similar lots have recently sold for $1,340,000. Over the past five years, the price of land in the area has increased 8 percent per year, with an annual standard deviation of 31 percent. A buyer has recently approached you and wants an option to buy the land in the next 12 months for $1,490,000. The risk-free rate of interest is 4 percent per year, compounded continuously. How much...
The management at Sage National Bank located in Key West, Florida, is calculating the key capital...
The management at Sage National Bank located in Key West, Florida, is calculating the key capital adequacy ratios for its third-quarter reports. At quarter-end, the bank’s total assets are $90 million and its total risk-weighted assets including off-balance-sheet items are $80 million. Tier 1 capital items sum to $4 million, while Tier 2 capital items total $2.5 million. Calculate Sage National’s leverage ratio, total capital-to-total assets, core capital-to-total risk-weighted assets, and total capital-to-total risk-weighted assets. Does Sage National meet the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT