Question

PYTHON QUESTION

2. Write a function called first_day_greater that takes two lists, L1 and L2 , representing the daily measured weights of rat 1 and rat 2, respectively, and returns the index of the first day for which the weight for the fist rat is greater than the weight of the second rat.If there are no such days then the function should return -1. You may NOT assume that L1 and L2 are the same length. Use the following to test your program: 1 f name -- main : L1- 15.1, 17.3, 12.3, 16.4 L2 = [ 15.0, 17.7, 12.5, 16.9 ] print (Test 1: (.format( first_day_greater(L1,L2) )) L2= [ 15.6, 17.9, 18.2, 16.5, 12.7 ] print(Test 2: (.format( first_day_greater(L1,L2) )) L2 = [ 15.9, 18.8, 11.4 ] print (Test 3: 0.format( first_day_greater(L1,L2))

0 0
Add a comment Improve this question Transcribed image text
Answer #1


The following is the code for your requirements as in the instructions.
I have added comments in the code for your reference.
The output and screenshot is at end of this answer.

Please ensure the code indented as shown in the attached image.

I have made sure to include all that is necessary for you to complete this assignment.
In case, if something is missing, drop me a comment.

If you have any queries, need changes in the code or need help in following the code, leave me a comment.
I will reply within reasonable time.

If this answer helps you with your assignment, do upvote it.
Your vote will motivate me to work better.

Here is the code.
//File: listgreater.py


#Method to return the index of L1 when L1[i] > L2[i]
def first_day_greater(L1, L2):
#Iterate from first index to MIN of len of either list
for i in range(0, min(len(L1), len(L2))):
#If the value at this index in list L1 is greater than L2, return this index
if L1[i] > L2[i]:
return i
#No values in L1 is greater than L2
return -1
#Tests
if __name__ == '__main__':
L1 = [15.1, 17.3, 12.3, 16.4]
L2 = [15.0, 17.7, 12.5, 16.9]
print("Test 1: {}".format( first_day_greater(L1, L2)))
L2 = [15.6, 17.9, 18.2, 16.5, 12.7]
print("Test 2: {}".format( first_day_greater(L1, L2)))
L2 = [15.9, 18.8, 11.4]
print("Test 3: {}".format( first_day_greater(L1, L2)))


And here is the output when you execute the code
//Output:

listgreater.py × I TERMINAL1: bash #Method to return the index of L1 when L1[1] > L2[1] def first_day_greater(L1, L2): amoeba@amoeba-w10 MINGW64 /e/ws/vscode/py 3 #Iterate from first index to MIN of len of either list for i in range(6, min(len(L1), len(L2))): python listgreater.p Test 1: Test 2: -1 Test 3: 2 5曰 #If the value at this index in list L1 is greater than L2, return this index if L1[i] > L2(i]: amoeba@amoeba-w10 MINGW64 /e/ws/vscode/py 9 return i 1e #No values in L1 is greater than L2 return -1 12 13 14 #Tests 16 17 18 19 20 21 L1 [15.1, 17.3, 12.3, 16.4] L2 [15.0, 17.7, 12.5, 16.9] print(Test 1: .format( first_day_ greater(L1, L2))) L2 [15.6, 17.9, 18.2, 16.5, 12.7] print(Test 2: .format( first_day_greater(L1, L2))) L2- [15.9, 18.8, 11.41 print(Test 3: .format( first day greater(L1, L2))) 23 24

Add a comment
Know the answer?
Add Answer to:
PYTHON QUESTION 2. Write a function called first_day_greater that takes two lists, L1 and L2 ,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can u clearly show me how to find a sample size (N) , A2, and can...

    can u clearly show me how to find a sample size (N) , A2, and can you also tell me why we are using an X Chart? Problem 1 A restaurant wants to control kitchen preparation time of dinner meals using an X chart. The process standard deviation is unknown. Each evening a manager takes a random sample of 14 dinner orders and measures and records their kitchen preparation time. Create an X Chart using data in the table below...

  • A gardener plants 300 sunflower seeds (of a brand called KwikGrow) and, after 2 weeks, measures...

    A gardener plants 300 sunflower seeds (of a brand called KwikGrow) and, after 2 weeks, measures the seedlings’ heights (in mm). These heights are recorded below. He is interested in testing whether the mean height of sunflowers grown from KwikGrow seeds is greater than 33 mm two weeks after planting. He decides to conduct a hypothesis test by assuming that the sampling distribution of the sample mean has a normal distribution. For the purposes of this question, you may assume...

  • We are interested in the relationship between the compensation of Chief Executive Officers (CEO) ...

    We are interested in the relationship between the compensation of Chief Executive Officers (CEO) of firms and the return on equity of their respective firm, using the dataset below. The variable salary shows the annual salary of a CEO in thousands of dollars, so that y = 150 indicates a salary of $150,000. Similarly, the variable ROE represents the average return on equity (ROE)for the CEO’s firm for the previous three years. A ROE of 20 indicates an average return...

  • PLEASE USE THE BELOW GIVEN DATA TO SOLVE THIS PROBLEM. INCLUDING THE BRIEF REPORT. THANK YOU....

    PLEASE USE THE BELOW GIVEN DATA TO SOLVE THIS PROBLEM. INCLUDING THE BRIEF REPORT. THANK YOU. Sales (Y) Calls (X1) Time (X2) Years (X3) Type 47 167 12.9 5 ONLINE 47 167 16.1 5 ONLINE 44 165 14.2 5 GROUP 43 137 16.6 4 NONE 34 184 12.5 4 GROUP 36 173 14.3 4 GROUP 44 160 14.1 4 NONE 34 132 18.2 4 NONE 48 182 14.1 4 ONLINE 41 158 13.8 4 GROUP 38 163 10.8 4 GROUP...

  • (For this question use the data file PerCapita Link). A researcher interested in examining how a...

    (For this question use the data file PerCapita Link). A researcher interested in examining how a state's per capita income may be affected by the percent of the state's adult population that has not completed high school and the percent of the state's population that is foreign born. (round answers to four decimal places) part b: Using regression analysis, determine how good of a fit the model is to the data. Explain (report the relevant statistic from the regression results)....

  • Census data was collected on the 50 states and Washington, D.C. We are interested in determining ...

    Census data was collected on the 50 states and Washington, D.C. We are interested in determining whether average lifespan (LIFE) is related to the ratio of males to females in percent (MALE), birth rate per 1,000 people (BIRTH), divorce rate per 1,000 people (DIVO), number of hospital beds per 100,000 people (BEDS), percentage of population 25 years or older having completed 16 years of school (EDUC) and per capita income (INCO). A MLR model has LIFE (y) as the response...

  • Data file: "STATE" "MALE" "BIRTH" "DIVO" "BEDS" "EDUC" "INCO" "LIFE" AK 119.1 24.8 5.6 603.3 14.1...

    data file: "STATE" "MALE" "BIRTH" "DIVO" "BEDS" "EDUC" "INCO" "LIFE" AK 119.1 24.8 5.6 603.3 14.1 4638 69.31 AL 93.3 19.4 4.4 840.9 7.8 2892 69.05 AR 94.1 18.5 4.8 569.6 6.7 2791 70.66 AZ 96.8 21.2 7.2 536.0 12.6 3614 70.55 CA 96.8 18.2 5.7 649.5 13.4 4423 71.71 CO 97.5 18.8 4.7 717.7 14.9 3838 72.06 CT 94.2 16.7 1.9 791.6 13.7 4871 72.48 DC 86.8 20.1 3.0 1859.4 17.8 4644 65.71 DE 95.2 19.2 3.2 926.8 13.1...

  • We consider a multiple linear regression model with LIFE (y) as the response variable, and MALE (...

    We consider a multiple linear regression model with LIFE (y) as the response variable, and MALE (x1), BIRTH (x2), DIVO (x3), BEDS (x4), EDUC (x5), and INCO (x6), as predictors. "STATE" "MALE" "BIRTH" "DIVO" "BEDS" "EDUC" "INCO" "LIFE" AK 119.1 24.8 5.6 603.3 14.1 4638 69.31 AL 93.3 19.4 4.4 840.9 7.8 2892 69.05 AR 94.1 18.5 4.8 569.6 6.7 2791 70.66 AZ 96.8 21.2 7.2 536.0 12.6 3614 70.55 CA 96.8 18.2 5.7 649.5 13.4 4423 71.71 CO 97.5...

  • I need help with my applied managerial statistics project Do a descriptive analysis(calculate mean, mode ,range...

    I need help with my applied managerial statistics project Do a descriptive analysis(calculate mean, mode ,range ,variance ,std ,deviation etc ) on each of the four variables sales ,calls, time, years and plot a histogram (using Excel)for each of the four variables. B Sales (Y) 37 38 40 117 45 43 34 37 137 138 44 45 37 38 43 46 45 Calls (X1) Time (X2) Years (X3) 117 14.8 117 15.3 15.6 117 15.8 120 18.2 120 13.6 131...

  • Complete the following four hypotheses, using α = 0.05 for each. The week 5 spreadsheet can...

    Complete the following four hypotheses, using α = 0.05 for each. The week 5 spreadsheet can be used in these analyses. 1. Mean sales per week exceed 42.5 per salesperson 2. Proportion receiving online training is less than 55% 3 Mean calls made among those with no training is at least 145 4. Mean time per call is 14.7 minutes Using the same data set from part A, perform the hypothesis test for each speculation in order to see if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT