Question: 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.
1. The Sum of Numbers Write a function called sum_nums which takes a positive integer value, n, as an argument and finds the sum of all integers on the interval [0,n] (i.e., all numbers up to and including n ). The function should use a for loop to complete this task and should return the sum computed. An example is shown below: sum_nums(5) \# output: 15 2. Distance Traveled The distance a vehicle travels can be calculated as follows: distance = speed time Write a function called distance_traveled which takes two positive floating point numbers, the speed of a vehicle (in miles per hour) and the hours it has traveled as arguments. For each hour that the vehicle traveled, calculate the total distance traveled, and print both the hour and the distance. An example is shown below. distance_traveled (40,3) \# output (via print) 1234080120 3. Celsius to Fahrenheit Table Write a function called convert_temp which takes no arguments. It should use a for loop to convert a list of the Celsius temperatures from 0 to 30 to their Fahrenheit equivalents. The conversion between the two temperature scales is given by, F=59C+32 Your function should print a table in which each row contains a Celsius value, and its associated Fahrenheit value, separated by tabs (hint: \t). As an example, convert_temp() \# output (via print) 032 133.8 3086.0 4. Speed Conversion Chart Write a function called convert_speed which takes a list of speeds in kilometers per hour (kph) as an argument. Your function should use a for loop to convert kilometers per hour ( kph ) to miles per hour (mph). Your function should print pairs of kph and mph adjacently. Each pair should appear on a different line. The conversion is given by, mph=0.6214kph Test the function using an input list containing the elements [40,50, 60..., 120], starting at 40 and running up to 120 in increments of ten. It would probably behoove you to figure out a way to generate this list automatically, rather than manually typing in all of its elements. The output should look like this, convert_speed ( [40,50,60,,120]) \# output (via print) 4024.855999999999998 5031.069999999999997 6037.284 7043.498 12074.568 5. Ocean Levels Assuming the level of the Earth's oceans continues rising at about 3.1 millimeters per year, write a function called ocean_levels which takes a starting level of the ocean in millimeters as an argument. Your function should use a for loop to calculate the cumulative (i.e., total) level of ocean visible after 25 years and should return this sum. An example is shown below: ocean_levels(2.1) \# output: 79.6 6. Circle Areas The formula to calculate the area of a circle is, A=r2 Assume that =3.14 and write a function to called circle_a reas which takes no arguments. Your function should use a for loop to calculate the area of a sequence of circles with increasing radius, starting with a radius of 1 and increasing in radius by 1 up to and including 8 . The function should print the area of each circle in increasing order on its own line. For example, circle_areas() \# output (via print) 3.14 12.56 28.26 50.24 78.5 113.04 153.86 200.96 7. Pennies for Pay Suppose that a person earns money over the course of a month based on the following pattern: they earn one penny on the first day, two pennies on the second day, four pennies on the third day, and so on with the daily pay doubling each day the employee works. Write a function called pay which takes the number of days the employee worked during the month as an argument. Your function should use a for loop to calculate how much the employee can earn in total for that month, and return this result. pay(3) \# output: 7 8. Weight loss If a moderately active person cuts their calorie intake by 500 calories a day, they can typically lose about 4 pounds a month. Write a function called weight_loss which takes a starting weight as an argument. Your function should print what the expected weight will be at the end of each month for the next 6 months if they stay on this diet. Print your results in separate lines. weight_loss (120) \# output (via print) 116 112 108 104 100 96 9. Calories Burned Running on a particular treadmill, you burn 3.9 calories per minute. Write a function called burned_calories which takes no parameter. Your function should use a loop to print the number of calories burned after 5,10,15,20,25, and 30 minutes. Print your result in separate lines. burned_calories( ) \# output (via print) 19.5 39.0 58.5 78.0 97.5 117.0 10. Membership Fees A country club, which currently charges $3,000 per year for membership, has announced it will increase its membership fee by 3 percent each year for the next five years. Write a function called fee which takes no arguments. Your function should use a loop to print the projected membership fees for each of the next five years in separate lines. fee () \# output (via print) 3090.0 3182.7 3278.1809999999996 3376.5264299999994 3477.8222228999994 11. Random Number Guessing Game Write a function called guess_number which takes an integer as a parameter. If the input argument to the function is larger than 39 , print the text "Too high, try again.". If the argument is smaller, print "Too low, try again.. If the input is exactly 39 , print "Congratulations! You figured out my number." guess_number(40) \# output (via print): Too high, try again. guess_number(39) \# output (via print): Congratulations! You figured out my number. guess_number(0) \# output (via print): Too low, try again. 12. The Greatest and Least of These Write a function called greatest_least which takes a list of integers as an argument. Your function should print the greatest and least number in the list in separate line. An example is shown below: greatest_least( [4,8,9,11,12,3,9]) \# output (via print) 12 3 13. Inflation The annual rate of inflation is the rate at which money loses its value. For example, if the annual rate of inflation is 3.0 percent, then in one year it will cost $1,030 to buy the goods that could have been purchased for $1,000 today. Put another way, a year from now $1,000 will only buy 1/1.03$1,000, or $970.87, worth of goods. Two years from now, $1,000 will only buy only 1/1.03 of $970.87, or $942.59 worth of goods. Write a function called rate_inf lation which takes an annual rate (between 1 percent and 10 percent, inclusive) as an argument. Your function should use a for loop to calculate how much $1,000 today will be worth each year for the next 10 years and return the final result (worth of $1,000 after 10 years). rate_inflation (6)# output: 538.615 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
Get step-by-step solutions from verified subject matter experts
