In: Computer Science
Python 3 Functions that give answers
Define and complete the functions described below.
* function name: get_name
* parameters: none
* returns: string
* operation:
Here, I just want you to return YOUR name.
* expected output:
JUST RETURNS THE NAME...TO VIEW IT YOU CAN PRINT IT AS
BELOW
>>> print(get_name())
John
* 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:
# just return the name
>>> print(get_full_name("John","Doe",True))
John Doe
>>> print(get_full_name("John","Doe",False))
Doe John
* 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:
Just return the value
>>> print(get_circle_area(5.0))
78.5
>>> print(get_circle_area(2.5))
19.625
Hopefully all yours doubt will clear if you have left with any doubt please let me know in comment. I will try my best to resolve that.
Here i am posting code and screenshot of program so that you have a clear idea about indentation and output with it.
Code :-
# Function will return name (John) def get_name(): # store name in variable name which will be return to main function name = "John" return name # Function will return full name based on first and last name def get_full_name(fname, lname, first_last): # If value of first_last is True means first name come first in full name then last name if first_last: # string concatenation of first name, space and last name return (fname + " " + lname) # If value of first_last is False means last name come first in full name then first name else: # string concatenation of last name, space and first name return (lname + " " + fname) # Function will calculate area of circle def get_circle_area(radius): # calculate area and store in area variable area = 3.14 * radius * radius # return area of circle to main function return area # print name using get_name function print(get_name()) # print full name using get_full_name function print(get_full_name("John","Doe",True)) print(get_full_name("John","Doe",False)) # print area of circle using get_circle_area print(get_circle_area(5.0)) print(get_circle_area(2.5))
Screeenshot of program :-
Screenshot of output :-