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.
26. Lowest Score Drop Write a function called lowest_drop which takes a list of positive floats as a parameter. Your function should return the average of these numbers after eliminating the smallest one. Do not use the built-in min function. lowest_drop ([75,80,60,100,100,85]) output: 88.0 27. Star Search A particular talent competition has five judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8.3, are allowed. A performer's final score is determined by dropping the highest and lowest score received, then averaging the three remaining scores. If there are multiple copies of the highest or lowest score, only drop one of them. Write a function star_search that takes the list of scores awarded by all the judges and return the final score of the performer. star_search ([8,9,7.5,6,8]) \# output: 7.833333 28. Primality Testing A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, the number 5 is prime because it can only be evenly divided by 1 and 5 . The number 6 , however, is not prime because it can be divided by 1,2,3, and 6. Write a function named is_prime which takes a positive integer as an argument and returns boolean True if the argument is a prime number, and boolean False otherwise. is_prime(127) \# output: True is_prime(25) \# output: False 29. Present Value Suppose you want to deposit a certain amount of money into a savings account and then leave it alone to draw interest for the next 10 years. At the end of 10 years (120 months) you would like to have $10,000 in the account. How much do you need to deposit today to make that happen? To find out you can use the following formula, which is known as the present value formula, P=(1+i)tF where P is the present value (amount you need to deposit today), F is the future value you want in the account, i is the monthly interest rate, and t is the amount of time you plan to let the money sit in the account (in months). Write a function called present_value which takes the future value, monthly interest rate, and number of years the money will grow as three arguments. The function should return the present value, which is the amount that you need to deposit today to have the specified future value. present_value (10000,3,10) \# output: 288.09 30. Future Value Suppose you have a certain amount of money in a savings account which is compounded monthly, and you want to calculate the amount that you will have after a specific number of months. The formula, which is known as the future value formula, is, F=P(1+i)t where P is the present value, F is the future value you want in the account, i is the monthly interest rate, and t is the amount of time the money sits in the account. Write a function called future_va vue which takes the account's present value, monthly interest rate, and number of months that the money as three parameters. Your function should compute and return the future value of the account after the specified number of months. future_value (288,3,120) \# output: 9996.764 31. Stock Profit The profit from the sale of a stock can be calculated as follows, profit =((NSSP)SC)((NSPP)+PC) Where NS is the number of shares purchase, SP is the sale price per share, SC is the commission paid, PP is the purchase price per share, and PC is the purchase commission paid. Write a function called stock_prof it which takes the number of shares, the purchase price per share, the purchase commission paid, the sale price per share, and the sale commission paid as five arguments. The function should return the profit (or loss) from the sale of stock. stock_profit (100,25,100,30,75) \# output: 525 32. Order Status The Middletown Wholesale Copper Wire Company sells spools of copper wiring for $100 each and ships them for $10 a piece. Write a function called order_status which takes the number of spools ordered and the number of spools in stock as two arguments. Your function should calculate the total bill of the order that the company can manage to ship and return this result. order_status (100,75) \# output: 8250 33. Hospital Cost Write a function that computes and returns the charges for a patient's hospital stay. Your function is called hospital_load which takes the number of days spent in the hospital, charges for hospital services (lab tests, etc.) per day, and hospital medication charges per day as three arguments. Your function is to return the total charges. hospital_load (4,100,75) \# output: 700 34. Population In a population, the birth rate is the percentage increase of the population due to births, and the death rate is the percentage decrease of the population due to deaths. Write a function called calc_population which takes: The starting size of a population (minimum 2) The annual birth rate The annual death rate as three arguments. our function calculates and returns the projected new size of the population after one year. The necessary equation is, N=P(1+B)(1D) Where, N is the new population size, P is the previous population size, B is the birth rate, D is the death rate. Annual birth rate and death rate are the typical number of births and deaths in a year per 1,000 people, expressed as a decimal. So, for example, if there are normally about 32 births and 26 deaths per 1,000 people in a given population, the birth rate would be .032 and the death rate would be .026. calc_population (35890080.032,0.026) \# output: 3607555.993344 35. Travel Expenses Write a function called travel_expense that calculates the total travel expenses of a company employee on a trip. Your function should take these as parameters The total number of nights spent away from home on the trip The amount of any round-trip airfare The amount of any car rentals Hotel expenses per night Your function should compute and return the total expenses that the company will face for traveling. travel_expense (7,1200,600,120 ) \# output: 2640 36. Coin Toss Write a function named coin_toss that simulates the tossing of a coin. Your function takes an integer (which must be either 1 or 2 ) as a parameter. If the number is 1 , the function should display "heads." If the number is 2 , the function should display "tails." coin_toss(1) \# output (via print): heads coin_toss(2) \# output (via print): tails coin_toss(0) \# output is undefined 37. Days Out Write a function called days_out that calculates the average number of days a company's employees are absent. Your function takes a list of the number of days each employee missed during the past year and the number of employees in the company as two parameters. Your function should calculate and return the average number of days the employees of the company exercised a leave. An example is shown below: days_out ([29,15,8,9,23,19],6)) \# output: 17.1666.. 38. Odd Number List Write a function named is_odd which takes no parameters. Your function should use a for loop to find all the odd numbers from 1 through 10 . If the number is an odd number, your function should print this number. If the number is an even number, your function should print " xxx is not an odd number" (you need to replace "xxx" with that number). is_odd () \# output (via print) 1 is not odd number is not odd number is not odd number is not odd number 9 10 is not odd number 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 namesStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started