![]() | |
Teachers Assignments Assignments Other Pages | Project 4: Assigned: Wed Sep 18 2024 Write each of the following functions without using loops. Remember to start with your file from last week. Don't erase anything. I highly recommend copying your old code to a new file first before editing your old file. Part 0, 2 points: Implement the Part 1, 1 points: Write a new function, >>> countdown_evens(9)
8
6
4
2
Blastoff! Tester.Part 2, 2 points: Write a new function, >>> partial_countdown(20, 3)
18
15
12
10
9
8
7
6
5
4
3
2
1
Blastoff! Tester.Part 3, 2 points: Write a function >>> print_interesting_multiples(20, 3)
20 40 60
>>> print_interesting_multiples(7, 0)
>>> print_interesting_multiples(6, 4)
6 12 18 24
>>> Remember your recursion steps! What's the condition for the base case going to be? Hint from above:>>> print_interesting_multiples(7, 0)
>>> What is the recursive call going to look like? Another hint:>>> print_interesting_multiples(5, 10)
5 10 15 20 25 30 35 40 45 50
>>> print_interesting_multiples(5, 9)
5 10 15 20 25 30 35 40 45 Tester.Part 4, 2 points: Write a function, >>> print_first_multiples(5, 10)
0 5 10 15 20 25 30 35 40 45
>>> print_first_multiples(5, 9)
0 5 10 15 20 25 30 35 40
>>> print_first_multiples(4, 5)
0 4 8 12 16
>>> print_first_multiples(100, 0)
>>> Remember, you can stifle printing a new line by using the end parameter for print, like this:>>> print('monkey', end = ' ')
monkey
>>> Tester.Part 5, 2 points: Write a function, Part 6, 2 points: Write a function, >>> print_whether_n_looks_prime(25, 3)
25 looks like it's prime.
>>> print_whether_n_looks_prime(25, 6)
25 is divisible by 5 .
>>> print_whether_n_looks_prime(25, 24)
25 is divisible by 5 .
>>> print_whether_n_looks_prime(25, 1)
25 looks like it's prime. It only needs to print that it's divisible by one factor: the highest factor less than n . You can assume that n will be at least 1 and that x will be less than n . Bonus Hint: for my solution, my recursive call looks like this: Tester.Part 7, 3 points: print_whether_n_looks_prime(67, 66) you'd just want to use a single parameter (and maybe a better-named function). We can fix this problem by writing a "wrapper" function that uses print_whether_n_looks_prime as the "worker" function by just making a single call to print_whether_n_looks_prime . (This Worker-Wrapper pattern is very common. Sometimes the underlying function with more parameters is called the "helper" function.) Add a new function called print_whether_prime(n) that just makes a single call to the worker. (That means you should be able to write this function in one line.)>>> print_whether_prime(25)
25 is divisible by 5 .
>>> print_whether_prime(27)
27 is divisible by 9 .
>>> print_whether_prime(29)
29 looks like it's prime. Tester.Part 8, 0 points: Expert Practice: exercise 5.6. Part 9, 0 points: Super Hard Expert Practice: Write a new function, >>> print_steps(4)
1,
1, 2,
1, 2, 3,
1, 2, 3, 4,
>>> Part 10, 3 points: Use the >>> input_greet()
Renee
Hi, Renee! Note: your code shouldn't print anything out before the user types in the name. Here is the Tester.Part 11, 2 points: Write a function, >>> royal_party()
Footman: Who is next in line?
> the Duke and Duchess of Monkington
Footman, loudly: Announcing the Duke and Duchess of Monkington!
Footman: Who is next in line?
> Sir Gibbonlon
Footman, loudly: Announcing Sir Gibbonlon!
Footman: Who is next in line?
> end party
>>> Note: the '>' should be typed by the program, not the user. Tester.Submitting your Project: Make sure all your code is in a file labelled with your user name (everything before the @ in your school email address) followed by |