Which of the following programs defines and calls a
function to compute and print the cube of
"2"?
(There could be more than one correct answer.)
def cube(n): return n * n * n print(cube(2)) |
def cube(n): return n ** 3 print(8) |
def cube(a): b = a * a return b * a c = 2 d = cube(c) print(d) |
def cube(n): n ** 3 print(cube(2)) |
Answer: Option 1 and Option 3
Explanation
Which of the following programs defines and calls a function to compute and print the cube...
Which of the following defines a function named print_bunny which takes more than one argument? Select all that apply. def print_bunny(ears, face, feet): print(ears) print(face) print(feet) print_bunny(bunny, how_many): print(bunny * how_many) def print_bunny(how_many): print('Bunny' * how_many) def PrintBunny(how_many): print(' (\\(\\ ' * how_many) print(' (-.-) ' * how_many) print(' O_(")(") ' * how_many) none of these def print_bunny(how_many): print(' (\\(\\ ' * how_many) print(' (-.-) ' * how_many) print(' O_(")(") ' * how_many)
#Which function has the most parameters? def Menu(): print ("Your Name Main Menu") print("1. Sum") print("2. Product") print("3. information") print("4. Quit") def Sum(x): x= x* 2 y = 10 answer = x+y return x,y,answer def Product(w,z): answer = w*z print (answer) def Calc(a,b,c): return a*b*c Question options: Product Calc Menu Sum
##8. A program contains the following function definition: ##def cube(num): ##return num * num * num ##Write a statement that passes the value 4 to this function and assigns its return value ##to the variable result. ##9. Write a function named times_ten that accepts a number as an argument. When the ##function is called, it should return the value of its argument multiplied times 10. ##10. Write a function named is_valid_length that accepts a string and an integer as ##arguments....
The following Implementation of the Fibonacci function is a correct, but inefficient, def fibonacci(n): if n <= 2: return 1 else: return fib(n - 1) + fib(n - 2) In more details, the code shown runs very slowly for even relatively small values of n; it can take minutes or hours to compute even the 40th or 50th Fibonacci number. The code is inefficient because it makes too many recursive calls. It ends up recomputing each Fibonacci number many times....
PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to: -define a recursive procedure/function and call it. -use syscall operations to display integers and strings on the console window -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9 if n <= 5 =...
Please use Python 3, thank you~ Write a program that: Defines a function called find_item_in_grid, as described below. Calls the function find_item_in_grid and prints the result. The find_item_in_grid function should have one parameter, which it should assume is a list of lists (a 2D list). The function should ask the user for a row number and a column number. It should return (not print) the item in the 2D list at the row and column specified by the user. The...
#What will the following programs print one mark for each correct answer ##Q5 1mark # tuple having integers my_tuple = (1, 2, 3) print(my_tuple) Answer: (1, 2, 3) ##Q6 1mark # tuple with mixed datatypes my_tuple = (1, "Hello", 3.4) print(my_tuple) ##Q7 1mark # nested tuple my_tuple = ("mouse", [8, 4, 6], (1, 2, 3)) print(my_tuple) ##Q8 4marks # tuple can be created without parentheses my_tuple = 3, 4.6, "dog" print(my_tuple) # tuple unpacking is also possible a, b, c...
What is wrong with the following function? def print_circle_area(radius): print(3.14*radius**2) a) the function body(code) is not indented correctly b) radius should be r c) it's missing a return value d) nothing seems to be wrong with this
Using the script story.py as an example and possible starting point, write a script that generates a story using multiple levels of function calls that mirror the structure of your story. Your script must have the following requirements: At least two functions must have randomly determined elements. Your script must accept some form of user input (e.g. name of the hero), which is then used throughout the story. The function structure of your script must have at least four levels....
in python 3 1. A program contains the following function definition: def cube(num): return num * num * num Write a statement that passes the value 4 to this function and assign its return value to the variable result. 2. Write a function named get_first_name that asks the user to enter his or her first name and returns it.