Florida Southern Sunset
CSC 2280: Intro Programming
(Fall 2024)

Syllabus

LMS

Teachers

Assignments
Assignments


Other Pages

Project 4:
Recursively Read this Title


Assigned: Wed Sep 18 2024
Due: 11:59:00 PM on Sat Sep 21 2024
Team Size: 1
Language: Python
Out of: 21 points


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 countdown(n) function that we did in class. (It's in the book too, on page 43.) Here's the Tester for this one.

Part 1, 1 points: Write a new function, countdown_evens(count), that works just like countdown, except it only prints even numbers. Example:

>>> countdown_evens(9)
8
6
4
2
Blastoff!
Tester.

Part 2, 2 points: Write a new function, partial_countdown(count, step), that works just like countdown when starting below 10, but for numbers above 10, it only prints out multiples of step. Example:

>>> 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(n, num_multiples), that prints multiples of n, starting with n, all on one line separated by spaces. Example:

>>> 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(n, num_multiples), that prints out the (actual first) integer multiples of n (starting with 0). Examples:

>>> 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, draw_squares_inside_squares(turtle, side_length), that has turtle first draw a square of the specified size, then draws another square inside that with it's corners at the midpoints of the outer-square's sides, then another inside that, etc, until it's asked to draw a square with side lengths of 1. (Stop at that point.) This picture shows what the first two squares should look like:
First two squares drawn by draw_squares_inside_squares.
That's only the first two squares! There's going to be many more in there! Hint: set the delay of the turtle to be really low so that it draws really fast (turtle.screen.delay(0.001)). When you've completed this, show it to me so I can record the grade.

Part 6, 2 points: Write a function, print_whether_n_looks_prime(n, x), that prints out whether parameter n is divisible by any number starting with x and going all the way down to 2. It should print a message like these cases:

>>> 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:
print_whether_n_looks_prime(n, x-1)
Tester.

Part 7, 3 points: print_whether_n_looks_prime is an ugly function to ask someone to use. If you were normally going to test whether 67 is prime, you wouldn't want to have to type

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, that takes a single integer parameter, n, and prints n lines, each starting from 1 and going one number further than the last. Like this:

>>> print_steps(4)
1,
1, 2, 
1, 2, 3, 
1, 2, 3, 4,
>>> 

Part 10, 3 points: Use the input() function to write input_greet, which is just like greet except that it waits to get the name from user input, like this:

>>> 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, that takes no parameters and announces newcomer names as they are entered until the string "end party"is entered. It should work like this:

>>> 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 _projects.py all in snake_case. (For example, my file name would be: kburke_projects.py.) It's very important to name your file correctly in order for me to grade it. Make sure your code runs, then upload it to the project on Canvas. (Don't submit code that doesn't run; you won't earn any points!) Your code should include solutions to all non-zero-point problems from Project 0 onwards. If there is already a file up on Canvas, delete that before uploading the new version or make sure your new file replaces that. (Sometimes Canvas adds a number after the file name. Don't worry about that, because it's something (freaking annoying) you don't have control of. I have a script that automatically deletes that.)