Question

In: Computer Science

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

Solutions

Expert Solution

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:


Related Solutions

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...
''' 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...
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...
Task 2 requires you to accurately complete the activities described in each question. Complete the answers...
Task 2 requires you to accurately complete the activities described in each question. Complete the answers in your own Excel document, putting your name at the top along with the Task and Task letter appropriate to each answer and submit below for your Assessor. a) Make the Journal entry to record the sale of merchandise that cost $6,000, for $10,000 cash. b) Record journal entries for the following transactions. Purchased office furniture for $3,200, agreed to pay the entire amount...
Problem: Write a C++ program that will implement and test the five functions described below that...
Problem: Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness. 1. minimum: takes an int array and the array's size as arguments. It should return the minimum value of the array elements. Do not use square brackets anywhere in the function, not even the parameter...
Complete this question by entering your answers in the tabs below. Required 1 Required 2 Complete...
Complete this question by entering your answers in the tabs below. Required 1 Required 2 Complete the above schedule of the company’s total costs and costs per unit. (Round the per unit variable cost and fixed cost to 2 decimal places.) Units Produced and Sold 69,000 89,000 109,000 Total costs: Variable costs $213,900 Fixed costs 390,000 Total costs $603,900 $0 $0 Cost per unit: Variable cost Fixed cost Total cost per unit $0.00 $0.00 $0.00
1)define variables. 2)define functions. 3)define data structure.
1)define variables. 2)define functions. 3)define data structure.
complete sudoku problem //*************************************************************** // D.S. Malik // // This class specifies the functions to solve...
complete sudoku problem //*************************************************************** // D.S. Malik // // This class specifies the functions to solve a sudoku problem. //*************************************************************** class sudoku { public: sudoku(); //default constructor //Postcondition: grid is initialized to 0 sudoku(int g[][9]); //constructor //Postcondition: grid = g void initializeSudokuGrid(); //Function to promt the user to specify the numbers of the //partially filled grid. //Postcondition: grid is initialized to the numbers // specified by the user. void initializeSudokuGrid(int g[][9]); //Function to initialize grid to g //Postcondition: grid =...
1. Define the 7 Levels of Evidence described in the Sewell textbook. 2. Define the term...
1. Define the 7 Levels of Evidence described in the Sewell textbook. 2. Define the term ‘research practice gap’ and name two causes. 3. Provide a brief definition of a ‘Just Culture’. 4. How can informatics be used to monitor errors and support a Just Culture? 5. What is BCMA and how does it contribute to patient safety? 6. Define telenursing and describe how it occurs. 7. Describe at least 2 examples of patient assessments that may be accomplished using...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT