Functions and Loops Mixed-Up Code Questions¶
Create a function called nums_x_to_y that takes in two integer parameter, x and y and uses a for loop to create and
return a list with numbers x to y. Note: ignore cases when y is not larger than x. For example, nums_x_to_y(1,10)
would return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].
Write a function called nums_x_to_y that takes in two integer parameter, x and y and uses a for loop to create and
return a list with numbers x to y. Note: ignore cases when y is not larger than x. For example, nums_x_to_y(1,10)
would return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].
Create a function count_by_x_to_y that takes in two integer parameter, x and y and uses a for loop to create and return
a list with numbers x to y. Note: ignore cases when y is not larger than x. Use a for loop to create and return a
list with numbers up to y by skip counting by x. For example, count_by_x_to_y(5,20) should return [0, 5, 10, 15, 20].
Write a function count_by_x_to_y that takes in two integer parameter, x and y and uses a for loop to create and return
a list with numbers x to y. Note: ignore cases when y is not larger than x. Use a for loop to create and return a
list with numbers up to y by skip counting by x. For example, count_by_x_to_y(5,20) should return [0, 5, 10, 15, 20].
Create a function called countdown that takes in one integer parameter seconds and creates a list of numbers that counts down from
seconds to 1, and then returns that list. Note: seconds must be greater than or equal to 1. For example, countdown(3) would return [3, 2, 1].
Write a function called countdown that takes in one integer parameter seconds and creates a list of numbers that counts down from
seconds to 1, and then returns that list. Note: seconds must be greater than or equal to 1. For example, countdown(3) would return [3, 2, 1].
Create a function add_odds_or_floor_division that takes in a parameter num_list and loops through the num_list.
If the number in num_list is odd, it gets added to result. Otherwise, it gets divided from the result, having the result be the floor value.
Then, return result. For example, add_odds_or_floor_division([-3, -5, -2, -9, 7.5, 10001, -5.3]) would return -1887.0.
Write a function add_odds_or_floor_division that takes in a parameter num_list and loops through the num_list.
If the number in num_list is odd, it gets added to result. Otherwise, it gets divided from the result, having the result be the floor value.
Then, return result. For example, add_odds_or_floor_division([-3, -5, -2, -9, 7.5, 10001, -5.3]) would return -1887.0.
Create a function strings_chars_less_than_len that takes in a strings_list
and returns a sorted new list with strings that are shorter in length than the original list.
For example, strings_chars_less_than_len(['hello', 'bye', 'me', 'mississippi', 'miss']) would return [‘bye’, ‘me’, ‘miss’].
Create a function strings_chars_less_than_len that takes in a strings_list
and returns a sorted new list with strings that are shorter in length than the original list.
For example, strings_chars_less_than_len(['hello', 'bye', 'me', 'mississippi', 'miss']) would return [‘bye’, ‘me’, ‘miss’].
Create a function print_lists(nums1, nums2) that takes two lists of numbers with the same length, nums1 and nums2,
and returns a list of strings in the form: “Num1: num1, Num2: num2” for each pair of items in the two lists.
For example, print_lists([3, 2], [8, 4]) would return ["Num1: 3, Num2: 8", "Num1: 2, Num2: 4"].
Write a function print_lists(nums1, nums2) that takes two lists of numbers with the same length, nums1 and nums2,
and returns a list of strings in the form: “Num1: num1, Num2: num2” for each pair of items in the two lists.
For example, print_lists([3, 2], [8, 4]) would return ["Num1: 3, Num2: 8", "Num1: 2, Num2: 4"].
Create a function sum_lists(nums1, nums2) that takes two lists of numbers with the same length, nums1 and nums2,
and returns a list of the totals of the two numbers for each pair of items in the two lists.
For example, sum_lists([3, 2], [8, 4]) would return [11, 6].
Write a function sum_lists(nums1, nums2) that takes two lists of numbers with the same length, nums1 and nums2,
and returns a list of the totals of the two numbers for each pair of items in the two lists.
For example, sum_lists([3, 2], [8, 4]) would return [11, 6].