Introduction to Computer Programming (Quiz questions Exam 1)
True
An expression attached to an "if" statement should evaluate to a Boolean data type. True False
B. False
Any sequence of alpha-numeric characters (numbers and letters) can be used as a variable name (i.e. "abc123" and "123abc" are both valid variable names) A. True B. False
C. String
In this sample code, what is the data type of x? x = input("Enter a number: ") A. Float B. Int C. String D. Boolean
False
The following line of code will cause your program to crash: #print( Hello World! ) True False
False
The following line of code will cause your program to crash: #print( Hello World! ) True False
True
The following line of code will cause your program to crash: print( Hello World! ) True False
A. True
The following variable "answer" will have a floating point number stored as its data type: answer = 4.0 + 2 * 2 - 5 A. True B. False
C. String
What is the data type of x? y = 100.7534 x = format(y, "<20.2f") A. Float B. Int C. String D. Boolean
B. "(with 20 spaces) 10,000.98"
What is the value of x? y = 10000.98347 x = format(y, ">20,.2f") A. "10,000.98 " B. " (with 20 spaces) 10,000.98" C. "10,000.98" D. 10000.98
B. the variable is initialized outside of the loop
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
C. When keep_on_going refers to a value equal to 998
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 keep_on_going refers to a value equal to 999
When will the following loop terminate? while keep_on_going != 999: A. When keep_on_going refers to a value less than 999 B. When keep_on_going refers to a value greater than 999 C. When keep_on_going refers to a value equal to 999 D. When keep_on_going refers to a value not equal to 999
B. **
Which mathematical operator is used to raise five to the second power in Python? A. / B. ** C. ^ D. ~
False
You always need to include "elif" and "else" statements after writing an "if" statement. True False
D. Interactive
magine that you have a single line of Python code that reads: print ("Hello, world!") If you wanted to run this statement and immediately see the result you could do so by using __________ mode in IDLE. A. Functional B. Object Oriented C. Script D. Interactive
D. A sequence of characters that represents textual information
A "string" is: A. A sequence of numbers that represents numeric information B. A programmatic construct that lets the programmer store information during the execution of a program C. A reusable command that the programmer can "call" to execute a series of statements D. A sequence of characters that represents textual information
A. A programmatic construct that lets the programmer store information during the execution of a program
A "variable" is: A. A programmatic construct that lets the programmer store information during the execution of a program B. A sequence of numbers that represents numeric information C. A sequence of characters that represents textual information D. A reusable command that the programmer can "call" to execute a series of statements
A. Accumulator
A loop variable used to keep a running total is called a(n) _____. A. Accumulator B. Total C. running total D. grand total
A. 68
After the execution of the following statement, the variable price will reference the value _____. price = int(68.549) A. 68 B. 69 C. 68.55 D. 68.54
B. float
After the execution of the following statement, the variable sold will reference the numeric literal value as a(n) _____ data type: sold = 256.752 A. int B. float C. str D. currency E. decimal
C. four lines
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. your_grade = 98
Consider the following statement in Python: a = 123 The variable 'a' is storing a: A. A string B. A numeric value C. A logical value
B. Argument
Consider this statement in Python: print ("One", "Two", "Three") "One" is considered a/n: A. The name of a function B. Argument C. A numeric literal D. A variable
C. 0 times
Given the following code, how many times will the string "Hello" print a = 5 b = 10 while a == 10: print ("Hello") A. 1 time B. 5 times C. 0 times D. An infinite number of times
D. An infinite number of times
Given the following code, how many times will the string "Hello" print a = 5 b = 10 while a == 5: print ("Hello") A. 1 time B. 5 times C. 0 times D. An infinite number of times
A. one
How many arguments does the "input" function expect to receive? A. one B. two C. zero D. any number of arguments
A. Float
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
True
Python supports two different division operators True False
B. False
T/F: The first thing that happens in a while loop is that it executes the entire code block located inside the while loop once. A. True B. False
B. Can be used to skip to the next loop iteration
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. a boolean condition
The "while" keyword must always be followed by: A. an "if" statement B. a boolean condition C. a variable D. the "print" function
C. I'm ready to begin
The output of print("I'm ready to begin") is: A. Im ready to begin B. "I'm ready to begin" C. I'm ready to begin D. I"m ready to begin E. error
A. Float
What is the data type of x? y = 5.2 x = 100 + 200 + 300 + 900 / y A. Float B. Int C. String D. Boolean
C. arithmetic operators, comparison operators, logical operators
Which is the order in which operators are executed (from first to last)? A. arithmetic operators, logical operators, comparison operators B. logical operators, arithmetic operators, comparison operators C. arithmetic operators, comparison operators, logical operators D. comparison operators, arithmetic operators, logical operators
C. your_grade = 98
Which of the following is both a good and valid variable name? A. 3rdAve = "Bowery" B. my name = "Sally" C. your_grade = 98 D. greeting! = "Hi, there!" E. x = "John" F. time? = 4.00 G. "my name" = "Mary"
C. x = 1000
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
B. 5 times
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
C. 24.0
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. 24.0
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. Two
Imagine you have the following incomplete code: if ______: print ("got here!") elif ______: print ("got here!") if ______: print ("got here!") If a valid boolean expression was filled into each blank, what is the maximum # of times the String "got here!" could theoretically be printed? A. None B. One C. Two D. Three
D. Three
Imagine you have the following incomplete code: if ______: print ("got here!") if ______: print ("got here!") if ______: print ("got here!") If a valid boolean expression was filled into each blank, what is the maximum # of times the String "got here!" could theoretically be printed? A. None B. One C. Two D. Three
C. 2
What is the ending value of the variable 'a' when the following program is run? a = 0 c = 0 while c < 3: if c % 2 == 0: a += 1 c += 1 A. 0 B. 1 C. 2 D. 3
B. while condition :
What is the format for the while clause in Python? A. while condition B. while condition : C. while condition statement D. while condition : statement
D. Repetition
What is the structure that causes a statement or a set of statements to execute repeatedly? A. Sequence B. Decision C. Module D. Repetition
C. x = 6, y = 7
What is the value of x and y respectively at the end of this while loop? x = 0 y = 1 while x < 5: y = y + x x = x + 2 A. x = 0, y = 1 B. x = 4, y = 11 C. x = 6, y = 7 D. x = 6, y = 13 E. x = 6, y = 6
B. fooooobar
What is the value of x? y = 5 x = "f" + "o"*y + "bar" A. fo5bar B. fooooobar C. fobar D. f ooooo bar
C. A String
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. If parts of the duplicated code have to be corrected, the correction has to be made many times.
What of the following are a result of writing programs as one long sequence structure? A. Duplicated code makes the program faster to write. B. Having a long sequence of statements makes it easy to find errors. C. If parts of the duplicated code have to be corrected, the correction has to be made many times. D. It does not make use of decision structures.
B. logic
What type of error produces incorrect results but does not prevent the program from running? A. syntax B. logic C. grammatical D. human
A. Condition-controlled loop
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. True
What will the following code print when run? x = 5 y = 10 print (x == 10 or y == 10) A. True B. False C. 5 == 10 or 10 == 10 D. Nothing will print
B. False
What will the following code print when run? x = 5 y = 10 print (x == y) A. True B. False C. 5 == 10 D. Nothing will print
5
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 = ____________
C. performing an arithmetic expression
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. if y > 10 and y < 50
Which of the following is the correct if clause to determine whether y is in the range 10 through 50? A. if 10 < y or y > 50 B. if 10 > y and y < 50 C. if y > 10 and y < 50 D. if y > 10 or y < 50
D. #print("Hello, World!
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!
False
You would use Python's "Interactive Mode" to write a long program that contains many lines of code. True False
B. float
After the execution of the following statement, the variable sold will reference the numeric literal value as a(n) _____ data type: sold = 256.752 A. int B. float C. str D. currency E. decimal
B. One
How many "*" characters will print when the following code is run? x = 5 y = 10 if x == y: print ("*") elif x != y: print ("*") elif x < y: print ("*") A. None B. One C. Two D. Three
A. True
T/F: the variable answer will have a floating point number stored as its data type? answer = 4.0 + 2 * 2 - 5 A. True B. False
A. Can be used to immediately end a loop iteration
The "break" 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