Intro to Computer Programming Midterm Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the data type of the variable x? x = "5.65" A. Float B. Int C. String D. Boolean

C

The following line of code will cause your program to crash: print( Hello World! ) (True/False)

True

The function header begins with the keyword _______ followed by the name of the function.

def

What would the following mathematical operations return if they were translated to Python without changes? Enter a single numeric value as your response.five plus six mod three times three = ____________

5

Imagine you had the following loops: for i in range(5): print (i, "-", sep="", end="") What will print when the program is run? A. 0-1-2-3-4- B. 0-1-2-3-4-5- C. 1-2-3-4- D. 1-2-3-4-5-

A

In this sample code, what is the data type of y? x = input("Enter a number: ") y = float(x) A. Float B. Int C. String D. Boolean

A

Consider the following loop: - while True: # statements go here How could you end this loop? A. use the "continue" statement inside the loop B. use the "continue" statement outside of the loop C. use the "break" statement inside the loop D. use the "break" statement outside of the loop

C

Consider the following program: a = 1 while True: a += 1 print ("#" * a) if a % 5 == 0: break How many lines of output will be generated? A. two lines B. three lines C. four lines D. five lines

C

Consider this statement in Python: print ("One", "Two", "Three") "print" is considered a/n: A. A numeric literal B. A variable C. The name of a function D. String

C

If value1 is 2.0 and value2 is 12, what is the output of the following command? print(value1 * value2) A. 24 B. value1 * value2 C. 24.0 D. 2.0 * 12

C

What kind of information is being stored in the variable x? x = "1005" A. An integer B. A floating point number C. A String

C

Which of the following is not a valid way to control a while-loop? A. checking an accumulator variable B. checking a boolean value C. performing an arithmetic expression D. performing a comparison expression

C

Which of the variables defined could potentially be printed on line 8? 1: x = 5 2: def foo(n): 3: y = n 4: def bar(): 5: z = 4 6: return z 7: x = bar() 8: print(VARIABLE) A. y,z B. n C. x D. x,y,z E. y F. z,x

C

It is possible to call one function from within the body of another function: (T/F)

True

It is possible to use the "range" function to generate a reverse range (i.e. 10 to 1): (T/F)

True

Python supports two different division operators (True or False)

True

T/F: the variable answer will have a floating point number stored as its data type? answer = 4.0 + 2 * 2 - 5

True

The following variable "answer" will have a floating point number stored as its data type: answer = 4.0 + 2 * 2 - 5 (True/ False)

True

A(n) _____ variable is initialized inside a function. A. global B. constant C. defined D. local

D

In Python, the variable in the for clause is referred to as the _____ because it is the target of an assignment at the beginning of each loop iteration. A. target variable B. loop variable C. for variable D. count variable

A

In the following nested loop, how many iterations does the inner loop complete during the execution of the program? cnt = 0 for x in range(10): for y in range(10): cnt += 1 print(cnt, end=" ") print() A. 100 iterations B. 10 iterations C. 90 iterations D. 9 iterations

A

What type of loop structure repeats the code based on the value of a boolean expression? A. Condition-controlled loop B. Number-controlled loop C. Count-controlled loop D. Boolean-controlled loop

A

A for loop is most useful for: (Choose all that apply) A. executing some statements for a specific number of iterations B. executing some statements for an unknown number of times C. executing some statements for as long as a certain condition is false D. executing some statements for as long as a certain condition is true E. executing some statements for each item in a list

A, E

Which symbol is used to delimit strings (select all that apply)? A. ' B. _ C. """ D. " E. - F. ,

A,C,D

Which of the following names are valid for function definitions: (choose all that apply) A. send_data_2_file B. 2ndPower C. my name D. name

A,D

Consider this statement in Python: print ("One", "Two", "Three") "One" is considered a/n: A. A numeric literal B. Argument C. The name of a function D. A variable

B

How many times will the foo() function be called in the following code sample? def foo(): print ("hi") def bar(): foo() foo() for x in range(5): bar() A. 5 B. 10 C. 0 D. infinite

B

How many times will this loop iterate? a = 0 while a < 5: a = a + 1 A. 4 times B. 5 times C. 6 times D. An infinite number of times

B

Imagine that you have the following function: def foobar(x): y = '@' * x return y What is 'x' in this function? A. the function name B. an argument C. a value that is being returned D. none of the above

B

Imagine you wanted to ask the user to enter in an unknown number of test scores. Which Python structure would be most appropriate? A. "for" loop B. "while" loop C. "if/elif/else" statement D. none of the above

B

The "continue" statement: A. Can be used to immediately end a loop iteration B. Can be used to skip to the next loop iteration C. Can be used to end your program completely D. Can be used to negate a boolean condition

B

The "while" keyword must always be followed by: A. an "if" statement B. a boolean condition C. a variable D. the "print" function

B

What is the format for the while clause in Python? A. while condition B. while condition : C. while condition statement D. while condition : statement

B

What is the value of x? y = 5 x = "f" + "o"*y + "bar" A. fo5bar B. fooooobar C. fobar D. f ooooo bar

B

When using accumulator with "while" loops you must ensure that: A. the variable is initialized inside of the loop B. the variable is initialized outside of the loop C. the variable has a data type of String D. the variable has a data type of Boolean

B

Which mathematical operator is used to raise five to the second power in Python? A. / B. ** C. ^ D. ~

B

A "string" is: A. A programmatic construct that lets the programmer store information during the execution of a program B. A reusable command that the programmer can "call" to execute a series of statements C. A sequence of characters that represents textual information D. A sequence of numbers that represents numeric information

C

Assume you wanted to perform some mathematical calculation using the variable "x" (such as adding 5 to its value) - which line of code would allow you to do this? A. x = "1000" B. x = "one thousand" C. x = 1000

C

When will the following loop terminate? while keep_on_going != 999 - 1 : A. When keep_on_going refers to a value equal to 999 B. When keep_on_going refers to a value not equal to than 999 C. When keep_on_going refers to a value equal to 998 D. When keep_on_going refers to a value not equal to 998

C

When would it be useful to use nested for loops? A. to iterate through student names in a roster B. to iterate through colors of the rainbow C. to iterate through the squares on a chessboard D. to iterate through the toys on a holiday wish list

C

Custom function definitions: A. Must be written before they are called by another part of your program B. Must declare a name for the function C. Must include information regarding any arguments (if any) that will be passed to the function D. all of the above

D

Which of the following lines of code is valid? A. print("Hello, World!) B. print("Hello, World!') C. """print("Hello, World!") D. #print("Hello, World!

D

Which of the following will correctly print the numbers 1-10? A. for i in range(10) B. for i in randrange(10) C. for i in range(1,10) D. for i in range(1,11)

D

What range is generated by the following call to the "range" function? for i in range(3, 0, 1): A. 3 2 1 B. 3 2 1 0 C. 0 1 2 D. 0 1 2 3 E. No range will be generated

E

The following line of code will cause your program to crash: #print( Hello World! ) (True/False)

False

You would use Python's "Interactive Mode" to write a long program that contains many lines of code. (True/False)

False

A(n) _______________ loop usually occurs when the programmer forgets to write code inside the loop that makes the test condition false.

Infinite

A "variable" is: A. A reusable command that the programmer can "call" to execute a series of statements B. A programmatic construct that lets the programmer store information during the execution of a program C. A sequence of characters that represents textual information D. A sequence of numbers that represents numeric information

b


संबंधित स्टडी सेट्स

4x4 places and people in the city 4th nine weeks 13

View Set