Welcome To Florida Sign
CSC 2280: Intro Programming
(Fall 2024)

Syllabus

LMS

Teachers

Assignments
Assignments


Other Pages

Project 5:
Follow your nose!


Assigned: Mon Sep 23 2024
Due: 11:59:00 PM on Thu Sep 26 2024
Team Size: 1
Language: Python
Out of: 25 points


In this project, you will write some awesome fruitful functions! Sweet! These functions should not print anything, just return their result.

Part 0, 2 points: Write the function, area_of_circle that returns the area of a circle with the radius supplied as an argument. (We either have or probably will go over this one in class.) This is a fruitful function, so it shouldn't print anything out, just return the value. You can test that a fruitful function isn't printing by executing it in an assignment statement in interactive mode:

>>> area = area_of_circle(1)
>>> print(area)
3.141592653589793
>>>
Notice that nothing is printed out by the first statement. Here is the Tester.

Part 1, 2 points: Write a function, area_of_triangle, that returns the area of a triangle with the given base and height as arguments. E.g.:

>>> area_of_triangle(5, 10)
25
Here is the Tester.

Part 2, 3 points: Write hypotenuse as described at the end of section 6.2. (You don't have to record each step of your coding.) Here is the Tester.

Part 3, 3 points: Write a function, right_triangle_perimeter(leg_a, leg_b), that takes two parameters for the lengths of the triangle legs and returns the perimeter of the entire right trangle.

>>> right_triangle_perimeter(3, 4)
12.0
>>> x = right_triangle_perimeter(2, 2)
>>> print(x)
6.82842712474619
Tester.

Part 4, 2 points: Write a function, area_of_rectangle_between_points(x0, y0, x1, y1), that returns the area of a rectangle (with vertical and horizontal sides) with opposite corners at (x0, y0) and (x1, y1). Tester.

Part 5, 3 points: Write a function, sphere_volume(radius), that returns the volume of the sphere with radius equal to that parameter. (By this point, you should be using math.pi for all estimates of pi.) I recommend using Python's interactive mode to do out the math for your tests. Tester.

Part 6, 3 points: Write a function, cylinder_volume(radius, height), that returns the volume of a cylinder with the given radius and height. Tester.

Part 7, 3 points: Use the previous two parts to easily write a function, capsule_volume(radius, length). A capsule is the shape that's a cylinder with a hemisphere at either end. The length of the capsule includes both hemispheres.

>>> capsule_volume(1, 20)
60.73745796940267
>>> v = capsule_volume(2, 10)
>>> print('v:', v)
v: 108.90854532444615
Tester.

Part 8, 1 points: Write a function, is_even(integer), that returns a boolean value indicating whether the argument is an even integer or not. In other words, it should return True if the argument is an even number, and False otherwise. Tester.

Part 9, 1 points: Write a function, is_odd(integer), that returns a boolean value indicating whether the argument is an odd integer or not. There's an extremely easy way to write this using function composition, which I want you to do. Tester.

Part 10, 1 points: Write a function, is_divisible(n, m), that returns True if n is divisible by m and False otherwise. Tester.

Part 11, 1 points: Write a function, is_square(n), that returns True if n is a perfect square integer and False otherwise. 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.)