When a function accepts arguments, the valid data types and (if relevant) value ranges for these...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
When a function accepts arguments, the valid data types and (if relevant) value ranges for these arguments are specified in the problem. The problem will also state what to do if an argument violates its value range (for example, if an argument must fall between 0 and 1, but 15 is used). Beyond this, the functions do not need to do any type checking--assume that all arguments are of the correct type. If an incorrect type is provided, and the program crashes with a TypeError or ValueError, then that is okay. If the types provided as arguments are correct, however, the function should not throw one of these errors. Additionally, it is important that the function work correctly over all valid values, and that arguments of the correct type but invalid value are handled in the manner that the question specifies. Functions and Arithmetic 1. Compose a function called calc_final_price] that accepts two numerical arguments: the original price of an item, and the tax rate applied to that item. The original price must be a floating point number that is greater than 0, and the tax rate must be an integer on the interval [0, 100] (e.g., a tax rate of 6 corresponds to a 6% tax rate, etc.). If the provided arguments do not fall in these ranges, the output of the function is undefined (i.e., no need error check-- whatever happens, happens). The function should return the final price of the item after accounting for taxes (initial price + taxes). A few examples: calc_final_price(35, 8) calc_final_price(150, 0) calc_final_price(0, 9) calc_final_price(-15, 12) calc_final_price(1500, 107) calc_disc_price(250, 25). calc_disc_price(1000, 100) calc_disc_price(123, 0) calc_disc_price(0, 25) 2. Compose a function called calc_disc_price) that accepts two numerical arguments: the original price of an item, and a discount rate. The original price must be a floating point number that is greater than 0, and the discount rate must be an integer on the interval [0, 100] (e.g., a discount rate of 25 corresponds to a 25% discount). If the provided arguments do not fall within these ranges, the output of the function is undefined. The function should return the final price of the item after applying the discount (initial price - discount). A few examples: display_backwards(10) #output (via print): #9 #8 #7 #6 output: 37.8 * output: 150 Loops 1. Compose a function display_backwards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x) in descending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, #5 #4 #output: undefined (can be anything) #output: undefined (can be anything) * output: undefined (can be anything). #3 #2 #1 # output: 187.5 # output: 0 # output: 123 # output: undefined (can be anything) display_backwards(-5) # (no text should be displayed) 2. Compose a function display_add_backwards that accepts a single positive integer (x) as an argument, and prints all odd integers on the interval [1, x) in descending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_odd_backwards (10) #output (via print): #9 #7 # 5 #3 # 1 display_odd_backwards(-5) # (no text should be displayed) 3. Compose a function display_forwards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_forwards(10) #output (via print): #1 #2 # 3 #4 #5 #6 #7 #8 #9 display_forwards(-5) # (no text should be displayed) 4. Compose a function display_even_forwards that accepts a single positive integer (x) as an argument, and prints all even integers on the interval [1, x) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_even_forwards(10) #output (via print): #2 #4 #6 #8 display_even_forwards(-5) # (no text should be displayed) 5. Compose a function [num_yrs that accepts a single numerical argument: the initial deposit amount. This argument should be a positive floating point number. If the argument is zero or negative, the output of the function is undefined, but the function must return some result after a finite amount of time. If the argument is valid, then the function should return the number of years that would be required for the investment to grow to a total of at least $10,000, with an interest rate of 5% compounded annually. You should solve this problem using a loop to simulate the accrual of interest, stopping when the target amount has been exceeded. As a few examples, num yrs(100) #output: 95 num yrs(150000) # output: 0 num_yrs(-12) # output: undefined (but must return num_yrs(0) something") # output: undefined (but must return something"). Branching 1. Compose a function called catc_bonus that accepts a single numerical argument: a sales amount. This argument should be a positive number. If the argument is not valid, the output of the function is undefined. This function should return the bonus awarded based on the sales amount using the following logic: If the sales amount is greater than $10,000, then the bonus about is 5% of the sales amount. Otherwise, the bonus amount is only 2% of the sales amount. For example, calc_bonus(15000) calc bonus(7000) calc_bonus(-10) 2. Compose a function called temp_feel that accepts a single numerical argument: a temperature. This argument should be a floating point number. This function should return a string based upon the input temperature, determined using the following logic: if the temperature is less than 40, return COLD, if it is between 40 and 60 (inclusive), return CHILLY, and if it is greater than 60, return NICE. For example. # output: 750 #output: 140 #output: undefined temp_feel(0) #output: COLD temp_feel(100) # output: NICE temp_feel(60) # output: CHILLY 3. Compose a function called floor_division that accepts two numerical arguments. It should return an integer, calculated by dividing the first argument by the second. If the division is not defined, the output of the function is undefined, but the function must not throw an error. For example, floor_division (5, 2) # output: 2 floor_division (100, 20) # output: 5 Iteration 1. Compose a function print_1st that accepts a single list as an argument. It should print all of the contents of the list without using a loop. For example, print 1st([1, 2, 3, 4]) # output (via print): 1, 2, 3, 4] print 1st([]) #output (via print): 2. Compose a function print_1st_one_by_one that accepts a single list as an argument. It should print each element of the list on its own line, in the same order they appear in the list. If the list is empty, print nothing. For example, print_1st_one_by_one([1, 2, 3, 4]) #output (via print): #1 # 2 #3 74 3. Compose a function print_1st_reverse that accepts a single list as an argument. It should print each element of the list on its own line, in reverse order. If the list is empty, print nothing. For example, print_1st_reverse([1, 2, 3, 4]) #output (via print): # 4 #3 #2 #1 List Processing 1. Compose a function called print_1st_even that accepts a single list of integers as an argument. It should print all even elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_even([1, 4, 6, 7, 8, 9, 10]) #output (via print) #4 #6 #8 #10 2. Compose a function called print_1st_odd] that accepts a single list of integers as an argument. It should print all odd elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_odd([1, 4, 6, 7, 8, 9, 10]) #output (via print) # 1 #7 #9 3. Compose a function called (1st_odd_even that accepts a single list of integers as an argument. It should return a new list, containing the square of each even element within the input list, and the cube of each odd element, in the same order in which the elements appear in the input list. The input list should remain unchanged following the function call. For example, 1st odd even([1, 4, 6, 7, 8, 9, 10]) # output: [1, 16, 36, 343, 64, 729, 100] 4. Compose a function called str_len that accepts a single list of strings as an argument. It should return the string from the input list having the longest length, or an empty string ("") if the list is empty. If there are several strings with the longest length, return the first one from the list. hint: you can use the len() function on strings to get their length. For example, str_len(["hello", "world", "abc", "123", "other stuff"]) # output: "other stuff" str_len([]) # output: When a function accepts arguments, the valid data types and (if relevant) value ranges for these arguments are specified in the problem. The problem will also state what to do if an argument violates its value range (for example, if an argument must fall between 0 and 1, but 15 is used). Beyond this, the functions do not need to do any type checking--assume that all arguments are of the correct type. If an incorrect type is provided, and the program crashes with a TypeError or ValueError), then that is okay. If the types provided as arguments are correct, however, the function should not throw one of these errors. Additionally, it is important that the function work correctly over all valid values, and that arguments of the correct type but invalid value are handled in the manner that the question specifies. Functions and Arithmetic 1. Compose a function called calc_final_price) that accepts two numerical arguments: the original price of an item, and the tax rate applied to that item. The original price must be a floating point number that is greater than 0, and the tax rate must be an integer on the interval [0, 100] (e.g., a tax rate of 6 corresponds to a 6% tax rate, etc.). If the provided arguments do not fall in these ranges, the output of the function is undefined (i.e., no need error check-- whatever happens, happens). The function should return the final price of the item after accounting for taxes (initial price + taxes). A few examples: calc_final_price(35, 8) calc_final_price(150, 0) calc_final_price(0, 9) calc_final_price(-15, 12) calc_final_price(1500, 107) calc disc price(250, 25). calc_disc_price(1000, 100) calc disc price(123, 0) calc disc_price(0, 25) 2. Compose a function called calc_disc_price) that accepts two numerical arguments: the original price of an item, and a discount rate. The original price must be a floating point number that is greater than 0, and the discount rate must be an integer on the interval [0, 100] (e.g., a discount rate of 25 corresponds to a 25% discount). If the provided arguments do not fall within these ranges, the output of the function is undefined. The function should return the final price of the item after applying the discount (initial price - discount). A few examples: display_backwards(10) #output (via print): #9 #8 #7 #6 output: 37.8 * output: 150 Loops 1. Compose a function display_backwards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x) in descending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, #5 #4 #output: undefined (can be anything) #output: undefined (can be anything) * output: undefined (can be anything). #3 #2 #1 # output: 187.5 # output: 0 # output: 123 # output: undefined (can be anything) display_backwards(-5) # (no text should be displayed) 2. Compose a function display_add_backwards that accepts a single positive integer (x) as an argument, and prints all odd integers on the interval [1, x) in descending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_odd_backwards (10) #output (via print): #9 #7 # 5 #3 # 1 display_odd_backwards(-5) # (no text should be displayed) 3. Compose a function display forwards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_forwards(10) #output (via print): #1 #2 # 3 #4 #5 #6 #7 #8 #9 display_forwards(-5) # (no text should be displayed) 4. Compose a function display_even_forwards that accepts a single positive integer (x) as an argument, and prints all even integers on the interval [1, x) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_even_forwards(10) #output (via print): #2 #4 #6 #8 display_even_forwards(-5) # (no text should be displayed) 5. Compose a function (num_yrs that accepts a single numerical argument: the initial deposit amount. This argument should be a positive floating point number. If the argument is zero or negative, the output of the function is undefined, but the function must return some result after a finite amount of time. If the argument is valid, then the function should return the number of years that would be required for the investment to grow to a total of at least $10,000, with an interest rate of 5% compounded annually. You should solve this problem using a loop to simulate the accrual of interest, stopping when the target amount has been exceeded. As a few examples, num yrs(100) #output: 95 num yrs(150000) # output: 0 num yrs(-12) num yrs(0) # output: undefined (but must return something") # output: undefined (but must return something"). Branching 1. Compose a function called catc_bonus that accepts a single numerical argument: a sales amount. This argument should be a positive number. If the argument is not valid, the output of the function is undefined. This function should return the bonus awarded based on the sales amount using the following logic: If the sales amount is greater than $10,000, then the bonus about is 5% of the sales amount. Otherwise, the bonus amount is only 2% of the sales amount. For example, calc bonus(15000) calc bonus (7000) calc bonus(-10) 2. Compose a function called temp_feel that accepts a single numerical argument: a temperature. This argument should be a floating point number. This function should return a string based upon the input temperature, determined using the following logic: if the temperature is less than 40, return COLD, if it is between 40 and 60 (inclusive), return CHILLY, and if it is greater than 60, return NICE. For example. temp_feel(0) temp_feel (100) # output: 750 #output: 140 #output: undefined #output: COLD # output: NICE temp_feel(60) # output: CHILLY 3. Compose a function called floor_division that accepts two numerical arguments. It should return an integer, calculated by dividing the first argument by the second. If the division is not defined, the output of the function is undefined, but the function must not throw an error. For example, floor_division (5, 2) # output: 2 floor_division (100, 20) # output: 5 Iteration 1. Compose a function print_1st that accepts a single list as an argument. It should print all of the contents of the list without using a loop. For example, print 1st([1, 2, 3, 4]) # output (via print): 1, 2, 3, 4] print 1st([]) #output (via print): 2. Compose a function print_1st_one_by_one that accepts a single list as an argument. It should print each element of the list on its own line, in the same order they appear in the list. If the list is empty, print nothing. For example, print_1st_one_by_one([1, 2, 3, 4]) #output (via print): #1 # 2 #3 74 3. Compose a function print_1st_reverse that accepts a single list as an argument. It should print each element of the list on its own line, in reverse order. If the list is empty, print nothing. For example, print_1st_reverse([1, 2, 3, 4]) #output (via print): # 4 #3 #2 #1 List Processing 1. Compose a function called print_1st_even that accepts a single list of integers as an argument. It should print all even elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_even([1, 4, 6, 7, 8, 9, 10]) #output (via print) #4 #6 #8 #10 2. Compose a function called print_1st_odd] that accepts a single list of integers as an argument. It should print all odd elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_odd([1, 4, 6, 7, 8, 9, 10]) #output (via print) # 1 #7 #9 3. Compose a function called 1st_odd_even that accepts a single list of integers as an argument. It should return a new list, containing the square of each even element within the input list, and the cube of each odd element, in the same order in which the elements appear in the input list. The input list should remain unchanged following the function call. For example, 1st odd even([1, 4, 6, 7, 8, 9, 10]) # output: [1, 16, 36, 343, 64, 729, 100] 4. Compose a function called str_len that accepts a single list of strings as an argument. It should return the string from the input list having the longest length, or an empty string ("") if the list is empty. If there are several strings with the longest length, return the first one from the list. hint: you can use the len() function on strings to get their length. For example, str_len(["hello", "world", "abc", "123", "other stuff"]) # output: "other stuff" str_len([]) # output: When a function accepts arguments, the valid data types and (if relevant) value ranges for these arguments are specified in the problem. The problem will also state what to do if an argument violates its value range (for example, if an argument must fall between 0 and 1, but 15 is used). Beyond this, the functions do not need to do any type checking--assume that all arguments are of the correct type. If an incorrect type is provided, and the program crashes with a TypeError or ValueError, then that is okay. If the types provided as arguments are correct, however, the function should not throw one of these errors. Additionally, it is important that the function work correctly over all valid values, and that arguments of the correct type but invalid value are handled in the manner that the question specifies. Functions and Arithmetic 1. Compose a function called calc_final_price] that accepts two numerical arguments: the original price of an item, and the tax rate applied to that item. The original price must be a floating point number that is greater than 0, and the tax rate must be an integer on the interval [0, 100] (e.g., a tax rate of 6 corresponds to a 6% tax rate, etc.). If the provided arguments do not fall in these ranges, the output of the function is undefined (i.e., no need error check-- whatever happens, happens). The function should return the final price of the item after accounting for taxes (initial price + taxes). A few examples: calc_final_price(35, 8) calc_final_price(150, 0) calc_final_price(0, 9) calc_final_price(-15, 12) calc_final_price(1500, 107) calc_disc_price(250, 25). calc_disc_price(1000, 100) calc_disc_price(123, 0) calc_disc_price(0, 25) 2. Compose a function called calc_disc_price) that accepts two numerical arguments: the original price of an item, and a discount rate. The original price must be a floating point number that is greater than 0, and the discount rate must be an integer on the interval [0, 100] (e.g., a discount rate of 25 corresponds to a 25% discount). If the provided arguments do not fall within these ranges, the output of the function is undefined. The function should return the final price of the item after applying the discount (initial price - discount). A few examples: display_backwards(10) #output (via print): #9 #8 #7 #6 output: 37.8 * output: 150 Loops 1. Compose a function display_backwards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x) in descending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, #5 #4 #output: undefined (can be anything) #output: undefined (can be anything) * output: undefined (can be anything). #3 #2 #1 # output: 187.5 # output: 0 # output: 123 # output: undefined (can be anything) display_backwards(-5) # (no text should be displayed) 2. Compose a function display_add_backwards that accepts a single positive integer (x) as an argument, and prints all odd integers on the interval [1, x) in descending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_odd_backwards (10) #output (via print): #9 #7 # 5 #3 # 1 display_odd_backwards(-5) # (no text should be displayed) 3. Compose a function display_forwards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_forwards(10) #output (via print): #1 #2 # 3 #4 #5 #6 #7 #8 #9 display_forwards(-5) # (no text should be displayed) 4. Compose a function display_even_forwards that accepts a single positive integer (x) as an argument, and prints all even integers on the interval [1, x) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_even_forwards(10) #output (via print): #2 #4 #6 #8 display_even_forwards(-5) # (no text should be displayed) 5. Compose a function [num_yrs that accepts a single numerical argument: the initial deposit amount. This argument should be a positive floating point number. If the argument is zero or negative, the output of the function is undefined, but the function must return some result after a finite amount of time. If the argument is valid, then the function should return the number of years that would be required for the investment to grow to a total of at least $10,000, with an interest rate of 5% compounded annually. You should solve this problem using a loop to simulate the accrual of interest, stopping when the target amount has been exceeded. As a few examples, num yrs(100) #output: 95 num yrs(150000) # output: 0 num_yrs(-12) # output: undefined (but must return num_yrs(0) something") # output: undefined (but must return something"). Branching 1. Compose a function called catc_bonus that accepts a single numerical argument: a sales amount. This argument should be a positive number. If the argument is not valid, the output of the function is undefined. This function should return the bonus awarded based on the sales amount using the following logic: If the sales amount is greater than $10,000, then the bonus about is 5% of the sales amount. Otherwise, the bonus amount is only 2% of the sales amount. For example, calc_bonus(15000) calc bonus(7000) calc_bonus(-10) 2. Compose a function called temp_feel that accepts a single numerical argument: a temperature. This argument should be a floating point number. This function should return a string based upon the input temperature, determined using the following logic: if the temperature is less than 40, return COLD, if it is between 40 and 60 (inclusive), return CHILLY, and if it is greater than 60, return NICE. For example. # output: 750 #output: 140 #output: undefined temp_feel(0) #output: COLD temp_feel(100) # output: NICE temp_feel(60) # output: CHILLY 3. Compose a function called floor_division that accepts two numerical arguments. It should return an integer, calculated by dividing the first argument by the second. If the division is not defined, the output of the function is undefined, but the function must not throw an error. For example, floor_division (5, 2) # output: 2 floor_division (100, 20) # output: 5 Iteration 1. Compose a function print_1st that accepts a single list as an argument. It should print all of the contents of the list without using a loop. For example, print 1st([1, 2, 3, 4]) # output (via print): 1, 2, 3, 4] print 1st([]) #output (via print): 2. Compose a function print_1st_one_by_one that accepts a single list as an argument. It should print each element of the list on its own line, in the same order they appear in the list. If the list is empty, print nothing. For example, print_1st_one_by_one([1, 2, 3, 4]) #output (via print): #1 # 2 #3 74 3. Compose a function print_1st_reverse that accepts a single list as an argument. It should print each element of the list on its own line, in reverse order. If the list is empty, print nothing. For example, print_1st_reverse([1, 2, 3, 4]) #output (via print): # 4 #3 #2 #1 List Processing 1. Compose a function called print_1st_even that accepts a single list of integers as an argument. It should print all even elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_even([1, 4, 6, 7, 8, 9, 10]) #output (via print) #4 #6 #8 #10 2. Compose a function called print_1st_odd] that accepts a single list of integers as an argument. It should print all odd elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_odd([1, 4, 6, 7, 8, 9, 10]) #output (via print) # 1 #7 #9 3. Compose a function called (1st_odd_even that accepts a single list of integers as an argument. It should return a new list, containing the square of each even element within the input list, and the cube of each odd element, in the same order in which the elements appear in the input list. The input list should remain unchanged following the function call. For example, 1st odd even([1, 4, 6, 7, 8, 9, 10]) # output: [1, 16, 36, 343, 64, 729, 100] 4. Compose a function called str_len that accepts a single list of strings as an argument. It should return the string from the input list having the longest length, or an empty string ("") if the list is empty. If there are several strings with the longest length, return the first one from the list. hint: you can use the len() function on strings to get their length. For example, str_len(["hello", "world", "abc", "123", "other stuff"]) # output: "other stuff" str_len([]) # output: When a function accepts arguments, the valid data types and (if relevant) value ranges for these arguments are specified in the problem. The problem will also state what to do if an argument violates its value range (for example, if an argument must fall between 0 and 1, but 15 is used). Beyond this, the functions do not need to do any type checking--assume that all arguments are of the correct type. If an incorrect type is provided, and the program crashes with a TypeError or ValueError), then that is okay. If the types provided as arguments are correct, however, the function should not throw one of these errors. Additionally, it is important that the function work correctly over all valid values, and that arguments of the correct type but invalid value are handled in the manner that the question specifies. Functions and Arithmetic 1. Compose a function called calc_final_price) that accepts two numerical arguments: the original price of an item, and the tax rate applied to that item. The original price must be a floating point number that is greater than 0, and the tax rate must be an integer on the interval [0, 100] (e.g., a tax rate of 6 corresponds to a 6% tax rate, etc.). If the provided arguments do not fall in these ranges, the output of the function is undefined (i.e., no need error check-- whatever happens, happens). The function should return the final price of the item after accounting for taxes (initial price + taxes). A few examples: calc_final_price(35, 8) calc_final_price(150, 0) calc_final_price(0, 9) calc_final_price(-15, 12) calc_final_price(1500, 107) calc disc price(250, 25). calc_disc_price(1000, 100) calc disc price(123, 0) calc disc_price(0, 25) 2. Compose a function called calc_disc_price) that accepts two numerical arguments: the original price of an item, and a discount rate. The original price must be a floating point number that is greater than 0, and the discount rate must be an integer on the interval [0, 100] (e.g., a discount rate of 25 corresponds to a 25% discount). If the provided arguments do not fall within these ranges, the output of the function is undefined. The function should return the final price of the item after applying the discount (initial price - discount). A few examples: display_backwards(10) #output (via print): #9 #8 #7 #6 output: 37.8 * output: 150 Loops 1. Compose a function display_backwards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x) in descending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, #5 #4 #output: undefined (can be anything) #output: undefined (can be anything) * output: undefined (can be anything). #3 #2 #1 # output: 187.5 # output: 0 # output: 123 # output: undefined (can be anything) display_backwards(-5) # (no text should be displayed) 2. Compose a function display_add_backwards that accepts a single positive integer (x) as an argument, and prints all odd integers on the interval [1, x) in descending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_odd_backwards (10) #output (via print): #9 #7 # 5 #3 # 1 display_odd_backwards(-5) # (no text should be displayed) 3. Compose a function display forwards that accepts a single positive integer (x) as an argument, and prints all integers on the interval [1, x) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_forwards(10) #output (via print): #1 #2 # 3 #4 #5 #6 #7 #8 #9 display_forwards(-5) # (no text should be displayed) 4. Compose a function display_even_forwards that accepts a single positive integer (x) as an argument, and prints all even integers on the interval [1, x) in ascending order, each on its own line. If the argument is not a positive integer, the function should print nothing (not even a blank line). For example, display_even_forwards(10) #output (via print): #2 #4 #6 #8 display_even_forwards(-5) # (no text should be displayed) 5. Compose a function (num_yrs that accepts a single numerical argument: the initial deposit amount. This argument should be a positive floating point number. If the argument is zero or negative, the output of the function is undefined, but the function must return some result after a finite amount of time. If the argument is valid, then the function should return the number of years that would be required for the investment to grow to a total of at least $10,000, with an interest rate of 5% compounded annually. You should solve this problem using a loop to simulate the accrual of interest, stopping when the target amount has been exceeded. As a few examples, num yrs(100) #output: 95 num yrs(150000) # output: 0 num yrs(-12) num yrs(0) # output: undefined (but must return something") # output: undefined (but must return something"). Branching 1. Compose a function called catc_bonus that accepts a single numerical argument: a sales amount. This argument should be a positive number. If the argument is not valid, the output of the function is undefined. This function should return the bonus awarded based on the sales amount using the following logic: If the sales amount is greater than $10,000, then the bonus about is 5% of the sales amount. Otherwise, the bonus amount is only 2% of the sales amount. For example, calc bonus(15000) calc bonus (7000) calc bonus(-10) 2. Compose a function called temp_feel that accepts a single numerical argument: a temperature. This argument should be a floating point number. This function should return a string based upon the input temperature, determined using the following logic: if the temperature is less than 40, return COLD, if it is between 40 and 60 (inclusive), return CHILLY, and if it is greater than 60, return NICE. For example. temp_feel(0) temp_feel (100) # output: 750 #output: 140 #output: undefined #output: COLD # output: NICE temp_feel(60) # output: CHILLY 3. Compose a function called floor_division that accepts two numerical arguments. It should return an integer, calculated by dividing the first argument by the second. If the division is not defined, the output of the function is undefined, but the function must not throw an error. For example, floor_division (5, 2) # output: 2 floor_division (100, 20) # output: 5 Iteration 1. Compose a function print_1st that accepts a single list as an argument. It should print all of the contents of the list without using a loop. For example, print 1st([1, 2, 3, 4]) # output (via print): 1, 2, 3, 4] print 1st([]) #output (via print): 2. Compose a function print_1st_one_by_one that accepts a single list as an argument. It should print each element of the list on its own line, in the same order they appear in the list. If the list is empty, print nothing. For example, print_1st_one_by_one([1, 2, 3, 4]) #output (via print): #1 # 2 #3 74 3. Compose a function print_1st_reverse that accepts a single list as an argument. It should print each element of the list on its own line, in reverse order. If the list is empty, print nothing. For example, print_1st_reverse([1, 2, 3, 4]) #output (via print): # 4 #3 #2 #1 List Processing 1. Compose a function called print_1st_even that accepts a single list of integers as an argument. It should print all even elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_even([1, 4, 6, 7, 8, 9, 10]) #output (via print) #4 #6 #8 #10 2. Compose a function called print_1st_odd] that accepts a single list of integers as an argument. It should print all odd elements within the list, each on its own line, in the same order in which they appear within the list. For example, print_1st_odd([1, 4, 6, 7, 8, 9, 10]) #output (via print) # 1 #7 #9 3. Compose a function called 1st_odd_even that accepts a single list of integers as an argument. It should return a new list, containing the square of each even element within the input list, and the cube of each odd element, in the same order in which the elements appear in the input list. The input list should remain unchanged following the function call. For example, 1st odd even([1, 4, 6, 7, 8, 9, 10]) # output: [1, 16, 36, 343, 64, 729, 100] 4. Compose a function called str_len that accepts a single list of strings as an argument. It should return the string from the input list having the longest length, or an empty string ("") if the list is empty. If there are several strings with the longest length, return the first one from the list. hint: you can use the len() function on strings to get their length. For example, str_len(["hello", "world", "abc", "123", "other stuff"]) # output: "other stuff" str_len([]) # output:
Expert Answer:
Answer rating: 100% (QA)
Here are the functions you requested 1 calcfinalprice function python def calcfinal... View the full answer
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
List three specific parts of the Case Guide, Objectives and Strategy Section (See below) that you had the most difficulty understanding. Describe your current understanding of these parts. Provide...
-
A general ledger trial balance at June 30, 2011, for Millar City is as follows: Millar City uses a purchases basis in accounting for supplies. Open encumbrances are considered constrained by the...
-
An electron in a one-dimensional infinite potential well of length L has ground-state energy E1. The length is changed to L' so that the new ground-state energy is E'1 = 0.5004. What is the ratio...
-
For each of the following, find a matrix B such that B2 = A. a. b. 2 9 -5 3 A =10 4 3 0 0 1
-
Draw an energy diagram for the cart in Figure 9.2 \(b\). Figure 9.2 The work done on a system is positive if the system gains kinetic energy and negative if the system loses kinetic energy. (a) Cart...
-
EBV is considering a $6M Series A investment for 6M shares of CP at $1 per share. The proposed capitalization table for Newco is as follows: (a) What are the OPP and APP for the Series A? (b) What is...
-
Answer the question by showing the calculation procedure. Verified the answer by using the MATLAB coding. Submit all the answers (calculation procedure & MATLAB code) to MS Team. For all of the...
-
Ellen wants to know how many copies of each book were sold. Write a SQL statement to obtain the necessary information you think Ellen wants? Use the following information: Ellen Novotny started an...
-
Annual demand for a particular halogen bulb is 4500 at a business that operates 300 days per year. The cost per order $ 220 and the holding cost per unit per year is $ 4.1 . The stockout cost is $ 30...
-
How does intentional misrepresentation differ from negligent and innocent misrepresentation?
-
What do plaintiffs have to prove in terms of causation?
-
True Or False Wrongful institution of civil proceedings cannot arise out of administrative or bankruptcy proceedings.
-
True Or False A plaintiff is most likely to recover for negligent misrepresentation when the defendant has a pecuniary interest in or makes false statements during a business transaction.
-
True Or False Settlements are more common in nuisance cases rather than CERCLA.
-
Give the electronic configuration of the oxygen (O) atom. Show it both as an electron-populated orbital diagram and as a list of orbitals with superscripts indicating the number of electrons....
-
SCHEDULE OF COST OF GOODS MANUFACTURED The following information is supplied for Sanchez Welding and Manufacturing Company. Prepare a schedule of cost of goods manufactured for the year ended...
-
Richard Brobston was hired by Insulation Corporation of America (ICA) in 1999. Initially, he was hired as a territory sales manager but was promoted to national account manager in 2003 and to general...
-
While adjusting a television antenna beside his mobile home and underneath a high-voltage electric transmission wire, Prince received an electric shock resulting in personal injury. He claims the...
-
Piedmont Electric Co. gave a list of delinquent accounts to Alexander, an employee, with instructions to discontinue electric service to delinquent customers. Among those listed was Todd Hatchery,...
-
What is the primary business of Satyam Computer Services Ltd?
-
In January 2009, approximately how many employees did Satyam Computer Services employ?
-
How much money did the Rajus earn from sales of Satyam stock in the eight years preceding the fraud revelation?
Study smarter with the SolutionInn App