# lab05.py - Required Questions import math def...

• Lab Report
• 3

This preview shows page 1 - 3 out of 3 pages.

###################### # Required Questions # ###################### import math def sine(x): """Returns the value of sine(x), where x is a value in radians. Use 0.0001 as a threshold. >>> from math import pi >>> sine(pi) #Notice how the value is very small but not quite 0. -1.482085565385205e-09 >>> sine(pi/2) 1.0 >>> sine((7 * pi)/2) -1.0 >>> sine(1.5) 0.9974949867067586 """ return 3*math.sin(x/3)-4*math.sin(x/3)**3 def is_palindrome(lst): """ Returns True if the list is a palindrome. A palindrome is a list that reads the same forwards as backwards >>> is_palindrome([1, 2, 3, 4, 5]) False >>> is_palindrome(["p", "a", "l", "i", "n", "d", "r", "o", "m", "e"]) False >>> is_palindrome([True, False, True]) True >>> is_palindrome([]) True >>> is_palindrome(["a", "v", "a"]) True >>> is_palindrome(["racecar", "racecar"]) True >>> is_palindrome(["r", "a", "c", "e", "c", "a", "r"]) True """ for i in range(len(lst)//2): if lst[i] != lst[-1-i]: return False return True def ab_plus_c(a, b, c): """Computes a * b + c. >>> ab_plus_c(2, 4, 3) # 2 * 4 + 3 11 >>> ab_plus_c(0, 3, 2) # 0 * 3 + 2 2 >>> ab_plus_c(3, 0, 2) # 3 * 0 + 2 2 """ if b == 0: return c else: return a + ab_plus_c(a, b-1, c)

Subscribe to view the full document.

def gcd(a, b): """Returns the greatest common divisor of a and b.
• Fall '18
• The Return, Greatest common divisor, Divisor

{[ snackBarMessage ]}

###### "Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern