4.2 For Loops - Lesson
4.3 While Loops - Lesson
Think you've got it?
Unit 4: Iteration - Review Assignment
1.Write a for loop to print every number between a (exclusive) and b (exclusive).
2.Write a function that takes in a list param a_list and returns a pancake scrambled version of the same list, as defined below.
3.Write a function print_all_elems_in(a_tup) that prints all of the elements in the tuple argument a_tup.
4.When might you use a while loop instead of a for loop?
5.Explain the break and continue statements.
6.Write a for loop to print every character in the string a_str.
7.Write a function get_great_movies(movie_ratings, min_rating=8) that accepts a list movie_ratings and a number min_rating as arguments and returns a list of all movie names with a rating that is greater than or equal to min_rating. Use a for loop in your solution!
8.Write a function all_values_in_dict(a_dict) that prints all values in the dictionary argument a_dict.
9.Write a while loop that prints all even numbers between 1 (inclusive) and 50 (inclusive).
10.Write a loop that continuously asks for user input via the input() function until the user inputs the string STOP (in all caps).
11.Write a while loop that prints all elements of the list a_lst in reverse order.
12.Write a while loop to print all elements in the list a_lst that do not contain the letter a (lowercased).
13.Write a recursive function count_down_from(n) that prints every number from n (inclusive) to 0 (inclusive). If n is initially less than 0, print the string "invalid input".
14.What is infinite recursion?
15.What are recursive functions?
16.Write a recursive function print_elem() that takes in two arguments, a list a_lst and an index i, and prints all elements from index i through the end of the list.
17.The recursive function recurse(n) currently counts down from n to 0, where n is expected to be a positive number. Modify the function so that it counts up from n to 0, where n is expected to be a negative number.