From brand guide: https://flsouthern.mediavalet.com/portals/fsc-brand-guidelines
CSC 2280: Intro Programming
(Fall 2024)

Syllabus

LMS

Teachers

Assignments
Assignments


Other Pages

Project 6:
Follow Your Nose by Following Your Nose!


Assigned: Fri Sep 27 2024
Due: 11:59:00 PM on Tue Oct 01 2024
Team Size: 1
Language: Python
Out of: 16 points


In this project, you will write some sweet recursive fruitful functions! Do not use any loops to write these functions.

Part 0, 1 points: Write the factorial function, as covered in class. Tester.

Part 1, 1 points: Write the fibonacci function, as covered in class. Tester.

Part 2, 3 points: Write a function, repeat_string(string, num_times), that returns a string repeated that many times:

>>> repeat_string("monkey", 3)
'monkeymonkeymonkey'
>>> repeat_string("antelope", 0)
''
>>> repeated = repeat_string("banana", 2)
>>> print(repeated)
bananabanana
Python already has an operator that does this automatically for you, but give it a try recursively. If you can't get this one, the rest will be nearly impossible. Tester.

Part 3, 2 points: Let's write fruitful versions for some of the void-recursive functions we wrote before. We'll name this one appropriately. Write is_prime_helper(n, k), that returns whether it is not true that n is divisible by all integers between 2 and k (inclusive).

>>> is_prime_helper(200, 150)
False
>>> is_prime_helper(200, 1)
True
Tester.

Part 4, 2 points: Now, of course, write the wrapper function: is_prime(n). Tester.

Part 5, 1 points: Create a function, triangular_number(n). The n-eth triangular number is the sum of the integers 0 to n. You've got to write this recursively, so it might help to think of the n-eth triangular numbers as the total number of boxes in a "staircase" of boxes up to height n. For example, the fourth triangular number is 4 because the first step is one box, the second is two boxes tall, the third is three, and the fourth is four boxes high. 10 = 1 + 2 + 3 + 4. Here's what the first five triangular numbers should return:

>>> triangular_number(0)
0
>>> triangular_number(1)
1
>>> triangular_number(2)
3
>>> triangular_number(3)
6
>>> triangular_number(4)
10
(I plan to do this problem with everyone in class.) Tester.

Part 6, 0 points: Expert Practice: tetrahedral_number(n). Tetrahedral numbers are like triangular numbers in 3-D. The i-th tetrahedral number is equal to the sum of the first i triangular numbers. Tester.

Part 7, 0 points: Expert Practice: Exercise 6.2. If this notation isn't clear to you, just ask me; I'm happy to walk you through it. This one's not actually all that hard once you get past the cases notation, but once you do it, the rest of the project will be extremely easy.

Part 8, 2 points: Exercise 6.3. Copy the three given functions in and use them to code up is_palindrome. Tester.

Part 9, 2 points: Exercise 6.4. (You can assume that a and b are both positive integers.)

>>> is_power(1, 3)
True
>>> is_power(10, 4)
False
>>> is_power(81, 3)
True
Hint: the base case is the same no matter what b is. Tester.

Part 10, 2 points: Exercise 6.5. This process is called Euclid's algorithm. Again, please assume that a and b are both integers. Once you have this one written, it will look completely obvious. (Also, why didn't they teach us this in grade school???)

>>> gcd(90, 40)
10
>>> x = gcd(40, 90)
>>> print(x)
10
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.)