Python has the same set of boolean operators you’re used to
Exceptions:
a < b < c is run as a < b and b < c
you can do some weird stuff with this:
a == b < c > d != q
a == b and b < c and c > d and d != q
if statementsif, elif and else statementsif .. elif .. elseelif not “else if”Write a Python function called absolute that takes one numeric argument (integer or float) n and returns the absolute value of n: if n is positive, it results n, if n is negative, it returns n * -1
Test cases:
Submit your solution (name your file absolute.py) to gradescope
import statementsYou can import a module that already exists in base python:
Or create a .py file and import that (overwrites the standard library if you create a .py file with its name)
math.piimport math
def circle_area(r):
'''
Given a radius r, this function calculates and returns the area of that circle
Arguments:
r (integer or float) -- radius of the circle
Returns:
And float (rounded at two decimals) representing the area of the circle of radius r
'''
area = math.pi * r**2
# return rounded area at two decimals
return round(area, 2)
if __name__ == "__main__":
assert circle_area(1) == 3.14
assert circle_area(2) == 12.57
assert circle_area(3) == 28.27
assert circle_area(4) == 50.27
assert circle_area(15) == 706.86
print("Passed all tests")Passed all tests
Prompt for generative AI: Give me a list of circle radii and their corresponding area rounded to two decimals
test.py
import_test.py