Python 1 Test 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What does the following code print out? for x in "banana": print(x) a. b a n a n a b. b c. none of these d. banana

????

What does the following code print out? True = False while True: print(True) break a. True b. This causes an error. c. None of these d. False

???? b. This causes an error?

T or F: A function is defined using the reserved word define.

False

T or F: Functions do not return a value called "fruitful" functions.

False

T or F: The else keyword in a while loop specifies a block of code to be executed when the loop is finished.

False

T or F: The range() function defaults to increment the sequence by 2, however it is possible to specify the increment value by adding a second parameter: range(30,1)

False

T or F: The range(6) is not the values of 0 to 5, but the values 0 to 6.

False

T or F: The return value of a function can not be assigned to a variable

False

T or F: A break statement can stop a while loop even if the while condition is true.

True

T or F: A for loop is used for iterating over a sequence (like a list or a string).

True

T or F: A function is called using the function name followed by parentheses around an arguments.

True

T or F: A nested loop is a loop inside a loop.

True

T or F: A while loop will execute as long as a condition is true.

True

T or F: An argument is a value that is passed to a function as input when the function is invoked.

True

T or F: Built-in function names are treated as reserved words.

True

T or F: Calling a function is the same thing as invoking a function.

True

T or F: Functions must be defined and called separately.

True

T or F: In Python, a function is some reusable code that takes arguments(s) as input, does some computation, and then returns a result or results

True

T or F: In most cases the "inner loop" will be executed one time for each iteration of the "outer loop".

True

T or F: The for loop does not require an indexing variable to set beforehand.

True

T or F: The looping structures are using include for and while loops.

True

T or F: The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specified number.

True

T or F: The two kinds of functions in Python are built-in functions and functions we define ourselves.

True

T or F: With the loop we can execute a set of statements, once for each item in a list.

True

T or F:A function can be called many times with different arguments each time it is called.

True

What is the iteration variable in the following Python program? friends=["Jack","Zero","Sally"] for friend in friends: print("Happy Halloween, "+friend) print("Done!") a. friend b. Sally c. Zero d. Jack

a. friend

What is the function in the following line of Python code? Biggest_Value = max("Hello World") a. max b. Biggest_Value c. "Hello World" d. =

a. max

The arguments of a function are also called the .... of the function. a. parameters b. lines c. tuples d. includes

a. parameters

What does the following code print out? fruits =["apples","bananas","cherry"] for x in fruits: print(x) a. none of these b. apple banana cherry c. apple d. apple banana

b. apple banana cherry

What is wrong with this Python loop? n = 5 while n > 0: print(n) print("All done") a. There should be no colon in the while statement. b. This loop will run forever. c. while is not a Python reserved word d. The print("All done") statement should be indented.

b. This loop will run forever.

Which of the options is not a reason to use a function? a. Your coding something complex that can be broken into small chunks. b. You want original and fresh code for every program c. Your creating a library of commonly used code. d. You write the code once and reuse it over and over

b. You want original and fresh code for every program

When parameters are given values they become..... a. results b. arguments c. return values d. options

b. arguments

Which option is not a built-in function? a. input b. computepay c. print d. max

b. computepay

What is a good description of the following Python program? zork = 0 for thing in [9, 41, 12, 3, 74, 15]: zork = zork + thing print("After " + str(zork)) a. finds the largest element in the list b. sums all the elements of the list c. finds the smallest element in the list d. computes the average of the elements in the list

b. sums all the elements of the list

Which reserved word indicates the start of an "indefinite" loop in Python? a. indef b. while c. for d. break

b. while

What does the following code print out? i=1 while True: if i%3==0: break print(i) i+=1 a. 1 2 b. None of these c. Syntax Error d. 1 2 3

c. Syntax Error

The result of a function is called..... a. print-out b. tuple c. return value d. send back

c. return value

What will the following Python program print out? smallest_so_far = -1 for the_num in [9, 41, 12, 3, 74, 15]: if the_num < smallest_so_far: smallest_so_far = the_num print smallest_so_far a. 41 b. 3 c. 74 d. -1

d. -1

How many times will the body of the following loop be executed? n = 0 while n > 0: print("Lather") print("Rinse") print("Dry off!") a. this is an infinite loop b. 1 c. 5 d. 0

d. 0

What does the break statement do? a. exits the program b. jumps to the "top" of the loop and starts the next iteration c. resets the iteration variable to its initial value d. exits the currently executing loop

d. Exits the currently executing loop

What does the following code print out? adj=["red","big"] fruits=["apple","banana"] for x in adj: for y in fruits: print(x,y) a. none of these b. red apple c. big red d. red apple red banana big apple big banana

d. red apple red banana big apple big banana

A function that does not return a value is a ...... function. a. hungry b. empty c. fruitful d. void

void


Set pelajaran terkait

Chapter 4-Applications of the Cognitive Schema Concept in Understanding How Consumers React to Products, Brands, and Marketing Agents

View Set

AP Calc FUN chart + particle motion justifications

View Set

Fundamentals: Infection control (ch. 39)

View Set

Computer Networking Hardware/Software/ETC

View Set