Question

Three students have written functions for squaring a number. They have used their function in a...

Three students have written functions for squaring a number. They have used their function in a program to square the number 4. Which of the following three programs includes a function for squaring any number and is called correctly in the program?

Select one:

a.

def squared(integer):
    return number * number


number = 4
result = squared(number)

b.

def squared():
    return number * number

number = 4
result = squared()

c.

def squared(integer):
    return integer * integer

number = 4
result = squared(number)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans is C

def squared(integer):
    return integer * integer

number = 4
result = squared(number)

in b the function does not have any argument and so it will gives the error because variable number is not define in the function.

in a the function receive the argument in variable called integer and in function they are using the variable named number that is not define in the function.so it also will gives the error,

so both a and b are incorrect. and c is the correct ans for you.

If you have any query regarding the answer please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Three students have written functions for squaring a number. They have used their function in a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using the following functions, modify the Python program written for the perfect number into TDD Java...

    Using the following functions, modify the Python program written for the perfect number into TDD Java program: 1) divisors (n) - takes a positive integer 'n' and return it's divisors sum as output. 2) isPerfect(n) - takes a positive integer 'n' as input and produces the result either as 'n is perfect' or 'n is not perfect using the function divisors()

  • 2. Write a program with three functions that will be called from the main function The functions will calculate the...

    2. Write a program with three functions that will be called from the main function The functions will calculate the volume, area and perimeter of a cuboid. You should able to pass three parameters such as length, width and height, and a function will return area, another will return volume and final one will return perimeter. Define all your variables in floating point numbers 3. Modify the problem#2 to calculate the volume, area and perimeter in a sing le function...

  • Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST b...

    Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST be written as specified. In your main code test all of the specified functions. Each function must have a comment block explaining what it does, what the parameters are and what the return value is. Please remember the following two guidelines: unless the purpose of the function is to generate output DO NOT write to the screen within the function unless the purpose...

  • Required functions def inputWithinRange (lowValue, highValue): This function will ask for a number from the keyboard....

    Required functions def inputWithinRange (lowValue, highValue): This function will ask for a number from the keyboard. The function will only return a value that is within the inclusive range of lowValue to highValue. If the entered value is not within the provided range, the function will ask again until the user has entered an acceptable value. The function will return the accepted value. def doContinue (prompt): This function will ask for a string using the prompt parameter. The function will...

  • In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt...

    In C++: A. Write 3 functions that are called in the program. 1. Function readInput prompt user to enter an integer to store to the parameter. 2. Function isPerfectSquare take an integer parameter and checks whether it's a perfect square, that it's square root is an integer. 3. Function min3 return the mainimum value of the parameter values, it shouldn’t use any if statement to compare the parameters but call min2 to do the comparison. Extra Credit: Function printPrimeFactorization print...

  • C++ Create three recursive functions that accomplish the following: Recursive Power Function this function will raise...

    C++ Create three recursive functions that accomplish the following: Recursive Power Function this function will raise a number to a power. The function should accept two arguments, the number to be raised and the exponent. Assume that the exponent is a non-negative integer. String Reverser function that accepts a string object as its argument and prints the string in reverse order. Sum of Numbers this function accepts an integer argument and returns the sum of all the integers from 1...

  • (Must be written in Python) You've been asked to write several functions. Here they are: yourName()...

    (Must be written in Python) You've been asked to write several functions. Here they are: yourName() -- this function takes no parameters. It returns a string containing YOUR name. For example, if Homer Simpson wrote this function it would return "Homer Simpson" quadster(m) -- this function takes a value m that you pass it then returns m times 4. For example, if you passed quadster the value 7, it would return 28. isRratedMovieOK(age) -- this function takes a value age...

  • 1. All functions should be written AFTER the main procedure. 2. A function prototype should be...

    1. All functions should be written AFTER the main procedure. 2. A function prototype should be written for each function and placed BEFORE the main procedure. 3. Each function should have a comment explaining what it does. 4. Each function parameter should have a comment explaining the parameter. 5. Prompt for the number of elements of the list. 6. Allocate an array whose size equals the number of elements specified by the user. 7. Read into the array the elements...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • 1. In Python, 'mutable' objects such as lists are passed to functions 'by reference'. This means:...

    1. In Python, 'mutable' objects such as lists are passed to functions 'by reference'. This means: a.) Changes made to the object within the function persist after the function completes b.) The function receives a copy of the object c.) Python keeps a history of where then object was used d.) Statements in the function can refer to the object by nickname 2. Which of the following is NOT a requirement for a Python function: a.) The function must have...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT