In: Computer Science
'''
Problem 2: Functions that give answers
Define and complete the functions described below.
The functions are called in the code at the very bottom. So you
should be
able simply to run the script to test that your functions work as
expected.
'''
'''
* function name: get_name
* parameters: none
* returns: string
* operation:
Here, I just want you to return YOUR name. The expected output
below assumes
that your name is Paul. Of course, replace this with the real
article.
* expected output:
# JUST RETURNS THE NAME...TO VIEW IT YOU CAN PRINT IT AS
BELOW
>>> print(get_name())
Paul
'''
'''
* function name: get_full_name
* parameters: fname (string)
lname (string)
first_last (boolean)
* returns: string
* operation:
Return (again, NOT print) the full name based on the first and last
names
passed in as arguments. The first_last argument will be True if you
should
return the name as <fname lname> and False if you shoudl
return the name
as <lname, fname>.
* expected output:
# AGAIN JUST RETURNS THE NAME...TO VIEW IT YOU CAN PRINT IT AS
BELOW
>>> print(get_full_name("Paul","York",True))
Paul York
>>> print(get_full_name("Paul","York",False))
York, Paul
'''
'''
* function name: get_circle_area
* parameters: radius (float)
* returns: float
* operation:
Return the area of a circle with the given radius. Use 3.14 as Pi.
And Google if for
some reason you've forgotten how to get the area of a circle.
* expected output:
# YET AGAIN JUST RETURNS THE VALUE
>>> print(get_circle_area(5.0))
78.5
>>> print(get_circle_area(2.5))
19.625
'''
# FUNCTIONS ARE CALLED BELOW HERE...NO NEED TO TOUCH
ANYTHING
# UNLESS YOU WANT TO COMMENT SOMETHING OUT TO TEST THINGS
# ALONG THE WAY...
print(get_name())
print(type(get_name())) # >>> <class 'str'>
print(get_full_name("Darth","Vader",True))
print(get_full_name("Luke","Skywalker",False))
print(type(get_full_name("Han","Solo",False))) # >>>
<class 'str'>
print(get_circle_area(5.0)) # 78.5
print(get_circle_area(2.5)) # 19.625
print(get_circle_area(12.25)) # 471.19625
Note: Make sure that indentation is correct. For reference, screenshot have also been attached. Indent the code accordingly.
#function name: get_name
#parameters: none
#returns: string
#operation: returns name, here it is john
def get_name():
return "john"
#function name: get_full_name
#parameters: fname (string),lname (string),first_last
(boolean)
#returns: string
#operation: returns first and last names based on first_last
def get_full_name(fname,lname,first_last):
if first_last:
return fname+" "+lname
else:
return lname+" "+fname
#function name: get_circle_area
#parameters: radius (float)
#returns: float
#operation: returns the area of circle with given radius
def get_circle_area(radius):
return 3.14*radius*radius
#function calls
print(get_name())
print(type(get_name())) # >>> <class 'str'>
print(get_full_name("Darth","Vader",True))
print(get_full_name("Luke","Skywalker",False))
print(type(get_full_name("Han","Solo",False))) # >>>
<class 'str'>
print(get_circle_area(5.0)) # 78.5
print(get_circle_area(2.5)) # 19.625
print(get_circle_area(12.25)) # 471.19625
Sample Run:
For indentation: