QUIZ

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

WHAT IS THE OUTPUT FOR EACH STATEMENT? 1. print(abs(-4.67) 2.print(pow(5, 3)) 3. print(pow(49, 0.5)) ***note*** when the exponent is 0.5 it computes teh squareroot. 4. print(int(34.8)) 5. print(round(6.9)) 6. import random print(random.randint(1,100))

1. 4.67 2. 125 3. 7.0 4. 34 5. 7 6. [1-100]

How many types of functions are there in Python? A: 3 B: 4 C: 5 D: 2

A: 3 built-in functions user-defined functions Anonymous functions

The following options is also called the anonymous function? A: lambda B: return C: User-defined D: Built-in

A: lambda Anonymous fucntions in Python are also called lamb functions. This is because they use the keyword lambda in their definition. ____ incorrect answers return The return statement in python is used within functions to return something to caller of the function. User-defined fucntion User defined function must have a name and you can give it any name that you like. Built-in The Python interpreter has a number of built in functions and types that are always available

The following argument is used to call a function? A: required B: variable number C: default D: keyword

A: required Required arguments are the type of arguments that have to be present when calling a function. These types of arguments also need to be in the correct order for a function to work as expected. ____ wrong answers Variable numbers There's can pass a variable number of arguments in Python by using the special (*) Asterix syntax. default Call arguement are does that take a default value if no argument value is passed during the fucntion call. Keyword We're arguments are very powerful and ensure that no matter in which order user passes arguements in the fucntion, they will always know which argument goes where.

Which of the following built-in function types is NOT available in Python? A: input([prompt]) B: get() C: map() D: print()

B __ the following built-in fucntions types are available in Python: input([prompt]) print() map()

Which of the following is used to return an iterator that applies a function to every item of the iterable yielding the results? A: lambda B: map() C: input([prompt]) D: print()

B: map() The map() function returns an iterator that applies a function to every item of the iterable yielding the results. Execute a specified function for each item in the iterable. ___ input([prompt]) Fucntion optionally print the prompt to the terminal. It then reads a line from the input and returns that lin print() Fucntion Prince object to the text stream file or the terminal. lambda Anonymous functions in Python so called lambda functions. These functions are called so because they use the keyword lambda in their definition.

The following function types is NOT available in Python? A: user-defined B: built-in C: default D: anonymous

C ___ The function types are available in Python: built-in user-defined anonymous

Which of the following statements is correct about the main() function? A: it is also called the lambda function. B: print objects to the text stream file or the terminal. C: it tells an operating system which piece of code to execute when a program is invoked. D: it is the information that needs to be passed to a function.

C That the programming languages require a special function, called main(), tells an operating system which piece of coach execute when our program is involved. _____ incorrect A: Anonymous functions in python are also called lambda functions. B: the print() the print function prints objects to the textstream file or the terminal. D: parameters are the information that needs to be passed to a function.

Which of the following keywords is used in the anonymous function? A: return B: finally C: lambda D: def

C: lambda Anonymous function in Python also called Lander functions. Can use the keyword lambda in the definition of these functions. ___ incorrect answers A: "return" keyword is used to end the execution of the function call and returns the result to a caller. B: the "finally" keyword is always executed after the try and except bloc D: The "def" where is used to create a new user-defined function..

Which of the following statements is true about a function in Python? A: It is a literal string used as a Python comment. B: It is a symbolic name that is used as a reference or point to an object. C: It is the collection of rules about which procedures should be evaluated first when evaluating an expression. D: It Is an easy way to group a few lines of code that implement features together.

D It is an easy way to group a few lines of code that implement features together. It is an integral the Python programming language. __ incorrect answers A: Documents string, or doc string for short is a literal string use as Python comment. B: A variable is a symbolic name that is used as a reference or pointer to an object. C: What are ev operations is the collection of rules about which procedure should be evaluated first when evaluating an expression.

Write the output of the following code in the answer text box below: number = 2.567 print("The absolute value of ", number, " is", abs(number)) number = -2.567 # note the negative sign print("The absolute value of ", number, " is", abs(number)) number = -2.567 # note the negative sign print("The integer portion of ", number, " is", int(number)) number = 12.87 print("The number", number, " round to the nearest integer is", round(number)) number = -2.1 # note the negative sign print("The number", number, " round to the nearest integer is", round(number))

The absolute value of 2.567 is 2.567 The absolute value of -2.567 is 2.567 The integer portion of -2.567 is -2 The number 12.87 round to the nearest integer is 13 The number -2.1 round to the nearest integer is -2

Given the function below answer the following questions. EXAMINE THE PYTHON FUNCTION DEFINTION. EXPLAIN THE PURPOSE OF THE INDENTATION. # description: this program uses a function to print a message # this is a function definition def printMessage(): print("Welcome to Python.") print("Learn the power of functions!") ############### Main program print("Hello Programmer!") # Function call printMessage()

The indented portion is the body of the function. It holds the print statements that will be called on. When the function is called, the function in the indented body will be executed. The purpose of the indentation in the function definition is to indicate that those lines of code will be executed when the function is called.

Given the function below answer the following questions. WHAT IS THE OUTPUT OF THE PROGRAM WHEN EXECUTED? # description: this program uses a function to print a message # this is a function definition def printMessage(): print("Welcome to Python.") print("Learn the power of functions!") ############### Main program print("Hello Programmer!") # Function call printMessage()

The program will print the first print request in the main program print ("Hello Programmer!") then it will go call upon the function definition and execute the print statements within the body of the def function. Out put will look like below:Hello Programmer! Welcome to Python. Learn the power of functions!

Write a possible output to the following code: import random import math number = random.randint(1,100) print("The random number is", number) number = 12.6 print("The smallest integer that is larger than", number, "is", math.ceil(number) )

The random number is 55 # could be any number between 1 and 100 The smallest integer that is larger than 12.6 is 13

In the Python code below: answer = pow(4,3) how many arguements does the pow function have? The first arguement is _____. The second arguement is ____.

There are 2 arguements in the pow function. The first arguement is 4. The second arguement is 3.

Why are the calls to the sqrt() , floor() and ceil() functions preceded by "math."?

They are in the math module. sqrt(), floor() and ceil() are all mathematical functions that have been specified with instructions in the math module. If you were to try to use any of these function without the parameters set in the math module, the result would be a syntax error as the program would not know what to do with the functions placed into the program without any parameters. For this reason the math module must go before the functions to help the function run properly by allowing it access to the extra instructions/parameters.

If a function contains more than one argument, do you think the order of the arguments makes a difference? Yes or No? Explain your answer using an example of a function with 2 arguments.

Yes. example would be the pow() function pow(4,3) is very different from pow(3,4) Take the pow() function. it is asking for the base number and the exponent. It is important to know which is which as the outcome will be very different. the base number will be the number that is being mulitiplied by a certain number of times. example: pow(7,2) the result would be 49 but if we reversed the numbers pow(2,7) the result would be very different as it would give you an 128.

What happens if you omit the import random line of code?

You will get an error a function defined in random is called/used.

What is the output for each of these function calls/lines of code? a. print(abs(4.5)) b. print(abs(-4.9)) c. print(int("678")) d. round(-5.6) e. import random random. randint(4, 10)

a. 4.5 b. 4.9 c. 678 d. -6 e. [4 -10]

Given the function below answer the following questions. # description: this program uses a function to print a message # this is a function definition def printMessage(): print("Welcome to Python.") print("Learn the power of functions!") ############### Main program print("Hello Programmer!") # Function call printMessage() a. What python keyword is used indicate that a code segment is a function definition? b. Of the function in the python program above--write the complete function header _______. c. The name of the function is in the function header. What is the name of the function?

a. def b. def printMessage(): c.printMessage

Write 2 lines of code that calculates the square root of 900 and stores the result in the variable answer. The first line must be the import statement.

import math answer = math.sqrt(900)

Write code that prints a random number between one and six. import random print(random.randint(1, 6))

import random print(random.randint(1, 6))

Is there a difference between the round() function and the int() function? If so, what is the difference?

int() takes a string that represents an integer or a floating point number as a arguement and returns the integer value. if it is a regular number it will just print out whatever is in the parenthesis. example: int("576") will result in 576 if it is a floating point number (number with a decimal) it will truncate(shorten) the number. example: int(42.6) will result in 42. round() takes a number as an argument and returns the integer nearest in the value to the number. if the number being rounded is a decimal value of 0.5 or higher it will groun up to the next integer. example: round(4.7) will result in 5. int function truncates/ignores the decimal part, the round function returns the next larger integer, if the decimal part is .5 or larger.

Complete the line of code below that prints the integer portion of the number 21.45.

int(21.45)

What is the purpose of "import random"? What happens if you omit that line of code?

it allows the code to use all the functions that are defined in the module random. You will get an error a function defined in random is called/used.

Write 2 lines of code 1. that prompts the user for a floating point number 2. prints the smallest integer that is larger than the number the user entered.

num = float(input("enter a float number: ")) print(math.ceil(num))

Fill in the blank below with the argument in the following code: number = 45.78 answer= round(number)

number The argument is what is inside the parentheses after the function name -- So in this case it is number The value of the argument is 45.78

Given the function below answer the following questions. WHAT SINGLE LINE OF CODE WOULD YOU ADD TO THE PROGRAM TO PRINT THE LAST TO LINES TWICE? WHERE WOULD YOU ADD THE CODE? # description: this program uses a function to print a message # this is a function definition def printMessage(): print("Welcome to Python.") print("Learn the power of functions!") ############### Main program print("Hello Programmer!") # Function call printMessage()

printMessage() after the last line in the main Python program -- below the first printMessage(). definitiondef printMessage(): print("Welcome to Python.") print("Learn the power of functions!") ############### Main program print("Hello Programmer!") # Function callprintMessage() Call the print again printMessage()

A user enters any number and that the number is stored in the variable userNumber. Write a line of code that reads the input and converts the input to a float. Then write another line of code that prints the positive value of the user's input.

userNumber = float(input("enter a float number: ")) print(abs(userNumber))


Kaugnay na mga set ng pag-aaral

anti bagsak reviewer ca ni baby girl iloveyousomuch 10000000000x

View Set

Microecon: Trade offs and Comparative Adv and the Market System

View Set

Geology 1500-11 EXAM 2 CH 7 METAMORPHIC ROCKS

View Set

ap gov campaign finance and super pacs

View Set

U.S. History - Ch. 16, Sec. 4 - Questions

View Set