Question

In: Computer Science

Python 3 Functions that give answers Define and complete the functions described below. * function name:...

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

Solutions

Expert Solution

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 :-


Related Solutions

Python 3 Forming Functions Define and complete the functions described below. * function name: say_hi *...
Python 3 Forming Functions Define and complete the functions described below. * function name: say_hi * parameters: none * returns: N/A * operation: just say "hi" when called. * expected output: >>> say_hi() hi * function name: personal_hi * parameters: name (string) * returns: N/A * operation: Similar to say_hi, but you should include the name argument in the greeting. * expected output: >>> personal_hi("Samantha") Hi, Samantha * function name: introduce * parameters: name1 (string) name2 (string) * returns: N/A...
''' Problem 2: Functions that give answers Define and complete the functions described below. The functions...
''' 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...
''' Problem 1: Formin' Functions Define and complete the functions described below. The functions are called...
''' Problem 1: Formin' Functions 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: say_hi * parameters: none * returns: N/A * operation: Uhh, well, just say "hi" when called. And by "say" I mean "print". * expected output: >>> say_hi() hi ''' ''' * function name: personal_hi...
''' Problem 1: Formin' Functions Define and complete the functions described below. The functions are called...
''' Problem 1: Formin' Functions 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: say_hi * parameters: none * returns: N/A * operation: Uhh, well, just say "hi" when called. And by "say" I mean "print". * expected output: >>> say_hi() hi ''' ''' * function name: personal_hi...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
which statements are true about Python functions? a)Different functions cannot use same function name b)a function...
which statements are true about Python functions? a)Different functions cannot use same function name b)a function always returns some value c)different function cannot use the same variable names d) function must use the same parameter names as the corresponding variables in the caller what benefits does structuring a program through defining functions bring? a) there is a possibility of reducing the number of variables and/or objects that must be managed at any cost at any one point b)the program is...
PYTHON: Complete these functions in the module: f2c, a function to convert Fahrenheit temperatures to Celcius....
PYTHON: Complete these functions in the module: f2c, a function to convert Fahrenheit temperatures to Celcius. c2f, a function to convert Celcius termperatures to Fahrenheit. Write f2c() and c2f() as functions that return a true value or False. In other words, these functions do not print — they return. A "true value", in this case, would be a number that corresponds to a temperature. If the user enters an invalid temperature, the function should return False. Create _main(), a function...
Give the name of cranial nerve X and one of its functions. Give the name and...
Give the name of cranial nerve X and one of its functions. Give the name and number of a cranial nerve - other than I, II, VIII, or X - and state one of its functions. Describe in detail the process of synaptic transmission. Start with the arrival of an action potential at a knob.  Include details regarding an IPSP and an EPSP example in the postsynaptic neuron. Also include clearing the synaptic cleft (gap). Use the back of this page...
python 3 please Define a function voweliest that takes as input a string and returns as...
python 3 please Define a function voweliest that takes as input a string and returns as output a tuple where the string that has the most vowels in it is the first element and the second is the number of vowels in that string. Note: don't worry about ties or capital letters Hint: consider defining and using a separate function that counts the number of vowels in a given string
Using Python 3, define mySum function that supposed to return the sum of a list of...
Using Python 3, define mySum function that supposed to return the sum of a list of numbers (and 0 if that list is empty), but it has one or more errors in it. Write test cases to determine what errors there are.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT