Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please use python and for loops L7 - Lab For today's lab you going to write five functions. Each function will make use of a
Please use python and for loops
L7 - Lab For today's lab you going to write five functions. Each function will make use of a for loop Note: DO NOT USE BUILT-IN LIST FUNCTIONS OR WHILE LOOPS TO COMPLETE THIS ASSIGNMENT The following describes what each function should do: sum_list(1) This function takes one parameter l, which is a list of numeric types. The function should loop over the list and return the sum of all of the numbers. Example print (sum list ([2,4, 5.5, 9, -10))) # Prints 10.5 every_ other(start,end) This function takes two parameters start and end. This function returns a list of every other number from start to end (including end, when possible) Example print (every-other (1,10)) # Prints [ 1, 3,5, 7,9 ] Notice 10 s not included because 10 is not in every other print (every-other (4,8)) # Prints [ 4,6,8 ] print (every-other (8,2)) # Prints [ count (item, container) This function takes two parameters an item we are count and a container we are looping over. This function should loop over the container element by element and count the number of times the item is in that container. This function should return that count. Example print (count ('a',"banana") print (count (8, [ 4, 6, 8, # Prints 3 # Prints 2 Notice 80 is not 8 80, 2, 8 ])) compare strings (string1, string2) This function takes two parameters string1 and string2. This function should return True if the strings are exactly the same and False otherwise. You should use a for loop to loop over one string checking if its characters each the characters in the other string. Do not use string1string2 we are practicing using loops Hint: Make sure the strings are the same length before you start looping. Example print (compare strings ("Orange", "orange")) 'Application')) # Returns False print (compare-strings ("App", # Returns False print grid (rows, cols) This function takes two parameters rows and cols. This function should print grid of rows * cols pound symbols Example print _grid (4,4) print grid (2,8) tttit 1 def sum_list(1): 2 pass 4 def every_other(start,end): 5 6 7 def count(item, container): pass pass 9 10 def compare_strings (string1, string2): pass 13 def print_grid(rows,cols): pass 15 16 # Test your code in main 17 def main(): print(sum_list([2,4,5.5, 9, -10])) print(every_other(1,1e)) print(every_other(4,8)) print(count('a', 'banana')) print(count(8, [4, 6, 8, 80, 2, 8 1)) print(compare_strings("Orange", "orange")) print(compare_strings("App", 'Application')) print_grid(4,4) print_grid(2,8) 23 25 28 # Do not change the code below 29 if" main"name 30 main()Step 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