Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code the following using python idle and be sure not to use the constructs in the prohibited list unless specified in the question. Note: 0

Code the following using python idle and be sure not to use the constructs in the prohibited list unless specified in the question.

Note: 0 is neither positive or negative, so if a function requires a positive input and does not explicitly state zero, then zero is invalid. Also, many of these problems accept a percentage as one of their arguments. All of these problems will expect the percentage to be an integer on the interval [0, 100]. For example, 6% would be represented as 6. You will probably need to convert this to .06 by dividing by 100 within the function itself before performing any calculations.

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

Write a function called predict_popu lation which takes the starting number of organisms, their average daily population increase (as a percentage of current population), and the number of days as three arguments. Your function should predict the size of a population of organisms. Your function should use a for loop to calculate the size of the population for each day and print each in separate lines. predict_population (100,20,3) # output (via print) 120.0 144.0 172.8 15. Savings Account Balance Write a function called savings which takes the starting balance and annual interest rate as two parameters. Your function should calculate the balance of a savings account at the end of a three-year period. Your function should use a for loop and should return the final balance. An example is shown below: savings (200,20) \# output: 345.6 16. Total and Average Rainfall Write a function called rainfall which takes a non-empty list of non-negative floats as a parameter. Each entry in this list represents the amount of rainfall on a given day. Your function should calculate the total rainfall and the average rainfall for the period and return the two calculated entities in the form of a list, where the first element is the total and the second is the average. rainfall( [3,2,0,1,9]) \# output: [15,3] 17. Times 10 Write a function named times_ten which takes a list of integers as a parameter. Your function should use print to display the product of each number within the list and 10 , in the same order that the elements appear within the list, with each number being on its own line. The contents of the original list should remain unchanged following a call to this function. For example, times_ten ([1,2,3,4,5]) \# output (via print) 10 20 30 40 50 18. Add threes Write a function named adding_threes, which takes a list of 0 s and 3 s. An example could be Ist1 = [3,0,0,3,3,3]. Your function should use a for loop and should do the following: if a list element is 0 then your function should print "Oops it is a missed bit". Otherwise, it should add 3 to an accumulator. For example, the sum for lst1=[3,0,0,3,3,3] would be 12 since there are four 3s. Your function should return the final value of the accumulator. An example is shown below: adding_threes ([3,3,3,0,3,0,0,3,3]) \# output: 18 \# output (via print) 0ops it is a missed bit 0ops it is a missed bit 0ops it is a missed bit 19. Artistic Solutions Paint Job Estimator Artistic Solutions, a painting company, has determined that for every 160 square feet of wall space, one gallon of paint and three hours of labor are required. The company charges $28 per hour for labor. Write a function called artistic which takes the number of rooms that are to be painted, a list containing the approximate square feet of wall space in each room, and the price of the paint per gallon as three parameters. Your function should calculate the total cost of the paint job and return this result. 20. Markup Write a function called calculate_retail which takes an item's wholesale cost and its markup percentage as two arguments and returns the retail price. For example: If an item's wholesale cost is $5.00 and its markup percentage is 100 percent, then the item's retail price is $10.00. calculate_retail (5,100)# output: 10.00 calculate_retail (15,25) \# output: 18.75 21. Celsius Temperature Write a function called convert_temp which takes in a temperature value (in Celsius) as a parameter. If the Celsius temperature is greater than or equal to 80 , then your function should convert the temperature to Fahrenheit and return it. Otherwise it should simply print "Celsius observation is less than 80". Use the following formula for temperature conversion: F=59C+32 convert_temp(45) \# output (via print): Celsius observation is less than 80 convert_temp(85) \# output: 185 22. Falling Distance The following formula can be used to determine the distance an object falls due to gravity in a specific time period, d=21gt2 where d is the falling distance (in meters) after t seconds of time have passed. g is the acceleration due to gravity, which has a value of 9.8ms1 Write a function called falling_d istance that accepts a list non-negative floats representing object falling times (in seconds) as an argument. For each entry the list, the function should print the distance, in meters, that the object has fallen during that time interval in separate lines. falling_distance ([3,6,9] ) \# output (via print): 44.145 176.58 397.305 23. Kinetic Energy In physics, an object that is in motion is said to have kinetic energy. The following formula can be used to determine a moving object's kinetic energy, Ek=21mv2 where Ek is the kinetic energy, in joules, m is the mass of the object, in kilograms, and v is the velocity of the object in meters per second. Write a function named kinetic_energy that takes an object's mass (in kilograms) and velocity (in meters per second) as two arguments. The function should return the amount of kinetic energy that the object has. kinetic_energy (25,100) \# output: 125000 24. Winning Division Write a function called winning_division that determines which of a company's four divisions (Northeast, Southeast, Northwest, and Southwest) had the greatest sales for a quarter. Your function should take a list of four elements as an argument, where each element is the total sales of the corresponding division (in the same order as listed above) over the last quarter. Your function should determine the largest sales among these four and return it. Do not use the built-in max function. winning_division( [150,75,160,200]) \# output: 200 25. Fuel Efficiency Three cars drive a 500 mile route. Write a function called calc_mpg which takes as an argument a list of positive floats representing the fuel consumed by the three cars in gallons to travel the 500 mile route. Your function should determine which car was the most fuel efficient and should return its mile/gallon rate as the output. calc_mpg ([20,15,19]) \# output: 33.333333.. directions. Using the following constructs will result in 0 (zero) for the entire submission (assignment, timed test, etc.). The restricted items are as follows: - Concepts not discussed in lectures yet - String functions - Member functions - Exceptions (can use) : /en () and x=x+[y1,y2,y3] - Built-in functions \& types - Exceptions (can use): str( ), readline( ), open(), close( ), write(), read(), range( ), .split() - Cannot use .append, .sort, etc. - Cannot use "Slicing" - Cannot use "list comprehension" - Cannot use "not in" (together) - Cannot use "in" - not allowed with conditionals - Exception (can use): with range () - Cannot use and \{\} - Exception (can use): mathematical operations (multiply \& exponents) - Data type functions - Exceptions (can use): int (), str (), float () - Break - Continue - Nested Constructs - Exceptions (can use): 2-D list - Multiple returns \& Multiple assignments - Recursion (not allowed unless the question explicitly states otherwise) - Functions within functions (Definitions) -- invocation is fine - Default Parameters - Global variables - Keyword as variable names

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago