Question

In: Computer Science

The following task does not involve writing program code: instead, you will be writing function signatures...

The following task does not involve writing program code: instead, you will be writing function signatures for hypothetical functions (you will be defining functions in subsequent tasks).

  1. For this task, you are presented with several 'hypothetical' functions. These aren't built-in Python functions: they are functions that you will have to define (i.e. implement, write) yourself later. however, you only need to write a signature for each hypothetical function listed here:
    1. toThePower(): takes two numbers e.g. x and y , and returns the value of (x to the power y). For example, toThePower(3,3) returns 27, and toThePower(-0.1,3) returns -0.001.
    2. quadruplicate(): takes a string, and returns a string consisting of three copies of that string concatenated together. For example, quadruplicate("na") returns "nananana", and quadruplicate("..?") returns "..?..?..?..?".
    3. subtract(): takes two numbers, and returns the difference between them. For example, subtract(10,3) returns 7, and subtract(2.2,5) returns -2.8.
    4. overlap(): We are not going to tell you exactly what it does, but we will give you a few examples: overlap("banana","analyze") returns 3 (not 4), overlap("abracadabra","abraham") returns 4 (not 5), overlap("foobar","red") returns 1, and overlap("foobar","bazinga") returns 0.
    5. multiplicate(): We are not going to tell you exactly what it does, but we will give you a few examples: multiplicate("x",5) returns "xxxxx", multiplicate("goo",3) returns "googoogoo", and multiplicate("never",0) returns "" (the empty string).

Solutions

Expert Solution

def toThePower(x,y):
return x**y;
  
def quadruplicate(string):
return string*4;
  
def subtract(x,y):
return x-y;
  
def multiplicate(string,times):
return string*times;
  

  
print(toThePower(-0.1,3))
print(quadruplicate("na"))
print(subtract(10,3))
print(multiplicate("goo",3))

Screenshot

Feel free to ask any doubts, if you face any difficulty in understanding.

Please upvote the answer if you find it helpful


Related Solutions

Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area...
Writing a Java Code Requirements of the JAVA program: Your task is to calculate geometric area for 3 shapes(square, rectangle and circle). You need to build a menu that allows users to enter options. Possible options are 'S' for square, 'R' for rectangle and 'C' for circle. HINT: you can use switch statement to switch on string input Invalid input should throw a message for the user. Example: Invalid input, please try again Each options should ask users for relevant...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
For this lab you are going to practice writing method signatures, implementing if statements, manipulating Strings,...
For this lab you are going to practice writing method signatures, implementing if statements, manipulating Strings, and improve your skills with for loops. The methods you will write will be part of a short trivia game, feel free to try it out after you finish.   import java.util.Scanner; public class Trivia { //TODO: isLeapYear //TODO: isPrime //TODO: aWord //TODO: reverse public static void main(String[] args){ Scanner answers = new Scanner(System.in); int score = 0; System.out.println("What year is a Leap Year?"); //...
This writing assignment will involve implementing and analyzing a behavior modification program on yourself. The behavior...
This writing assignment will involve implementing and analyzing a behavior modification program on yourself. The behavior is ANXIETY OF MEETING NEW PEOPLE. This assignment is to develop your own functional behavior assessment. A minimum of 3 paragraphs per question is required. Modification Plan: In this section, you need to describe your assessment and intervention plan. How will you collect data on the behavior in order to evaluate whether or not it is changing? Describe any forms or graphs you plan...
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
For this writing task, you'll need to respond to the following scenario: Who are you? You...
For this writing task, you'll need to respond to the following scenario: Who are you? You work as department head in the information technology (IT) department at First Federal Bank. Part of your job is to conduct an ongoing assessment of risk for the institution and to recommend proper controls. Banking systems should be able to quickly collect and edit information, summarize results, and promptly correct any errors. You have identified a possible threat to "timeliness" of information. You have...
PROGRAM DESCRIPTION: In this assignment, you are provided with working code that does the following: 1....
PROGRAM DESCRIPTION: In this assignment, you are provided with working code that does the following: 1. You input a sentence (containing no more than 50 characters). 2. The program will read the sentence and put it into an array of characters. 3. Then, it creates one thread for each character in the sentence. 4. The goal of the program is to capitalize on each letter that has an odd index. The given program actually does this but lacks the synchronization...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user to enter a part into the inventory, take a part from the inventory, or quit. You are provided with the InvItem class (InvItem.h) and a partial Driver.cpp. You will be creating a DynamicStack class that should implement a Stack data structure. The DynamicClass should be implemented as a template class to allow any data type be added/removed from the stack. You will submit three...
Your Task: Write a calculator Program with following functions (lack of function will result in a...
Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user. 1 - Add 2 - Subtract 3 - Multiply 4 - Divide 5 - Raise X to the power Y 6 - Finds if a number is even or odd 0 - Quit...
Your Task: Write a calculator Program with following functions (lack of function will result in a...
Your Task: Write a calculator Program with following functions (lack of function will result in a grade of zero). Your program must have the following menu and depending on the users choice, your program should be calling the pertaining function to display the result for the user. 1 - Add 2 - Subtract 3 - Multiply 4 - Divide 5 - Raise X to the power Y 6 - Finds if a number is even or odd 0 - Quit...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT