Starting from:

$34.99

CS104 Homework 03 Solution


1.Please implement a function that takes a number as its argument and returns whether the number is prime or not. For example, let’s assume that call your function is_prime_number, is_prime_number(4) returns False, is_prime_number(7) returns True.
2.  The surface area of an elliptic cylinder is calculated as the sum of all its surfaces. Please implement the following three functions and demonstrate that it works for an example.
a) A function that takes the radii of the elliptic cylinder and returns the area of the elliptic surface.
b) A second function which takes the radii and height of the cylinder and returns the area of the lateral surface.
c) Implement and use a third function that uses the first two functions and computes and returns the total surface area of an elliptic cylinder.
d) Please declare pi=3.141592 only once in your file and use this variable other places whenever necessary.
3. (25 pts) Write a Python program that defines a function in order to print the following on the screen. The properties of this function must be as follows:
a) Your function must accept an argument called height which will be used to figure out the height of the triangle.
b) Your function must return the sum of all integers on the last line of the triangle. For example 16 for height=4, 4 for height =2, and 49 for height=7.
c) Your function must use another function called get_row to figure out the row to be printed. This function must get the row height and return the necessary line. For example, it shall return “1” for row_height=1, “1 2 1” for row_height=2, “1 2 3 4 5 4 3 2 1” for row_height=5.
d) Your function must use a loop to call the get_row function and print the result to the screen.



More products