Download Quiz-1-Slides

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
What type of data can a variable hold?
•
•
•
•
A: Numbers
B: Strings
C: A & B
D: Practically everything
Which of the following *is* a valid
variable name?
A. ninety_nine_balloons
B. ninety nine balloons
C. 99_balloons
Which of the following *IS NOT* a
string?
A. “42”
B. ‘42’
C. 42
What would happen if you attempt to
assign a value to a variable that does
not exist?
Example: some_variable = 235
A. Nothing happens
B. “some_variable” now holds the value 235
C. Python generates an error
What would happen if you attempt to
PRINT a variable that does not exist?
Example: print(foo)
A. Nothing happens
B. PRINT outputs and empty string
C. Python generates an error
What is the value of my_var after the
following execution sequence?
>>> my_var = 0
>>> my_var = 7
>>> my_var = my_var + 1
A. 7
B. 8
C. 0
Which of the following are control
structures?
A.
B.
C.
D.
E.
FOR
IF
input()
A&B
A, B, & C
A comment in Python is indicated by a:
A.Colon (:)
B.Dollar sign ($)
C.Asterisk (*)
D.Pound Sign (#)
Which variable is properly named?
A.
B.
C.
D.
E.
MyVariable
myVariable
my_variable
My_Variable
My Variable
What is the default data type of all
user input?
A.int
B.string
C.float
D.main
How do we obtain user input?
A.input()
B.print()
C.FOR
D.float()
How many times will this loop?
for i in range(7):
pass
A.0
B.7
C.8
D.6
Ask the audience: Why do we use
“pass” below?
for i in range(7):
pass
How much will the variable “i” equal at
the end of the loop?
for i in range(8):
pass
A.0
B.6
C.7
D.8
E.9
What is the value of x after this loop?
x = 1
for i in range(3):
x = i * 2
A.0
B.3
C.6
D.8
E.4
What data type holds decimal
numbers?
A.int
B.float
C.char
D.string
How many times will the PRINT get
called?
for i in range(8):
for j in range(7):
print("hello")
A. 0
B. 7
C. 8
D. 42
E. 56
Which of the following *IS NOT* a
relational operator (used in IF
statements)
A.<
B.==
C.!=
D.=
E.>=
Which Checks Get Passed?
x = 25
if x == 25:
print("passed
if x > 25:
print("passed
if x < 25:
print("passed
if x > 1:
print("passed
1st check")
2nd check")
3rd check")
4th check“)
Answer
Check 1
Check 2
Check 3
Check 4
A
Yes
No
No
Yes
B
Yes
No
No
No
C
No
Yes
No
Yes
D
Yes
Yes
Yes
Yes
What data type holds whole numbers?
A.int
B.float
C.char
D.string
What is the output?
A = ‘this’
B = “that”
print(a + b)
A.Python throws an error
B.this that
C.‘this’”that”
D.thisthat
What does x equal?
x = input(“Enter x: “)
(we enter: -2 * 3 + 5)
A.-16
B.-1
C.‘-2 * 3 + 5’
D.Python throws an error
What is the value of x after the
following operation?
x = 10 // 3
A.0
B.3.333333333
C.3
D.1
What is the result?
4 * 1 // 2
A. 2
B. 0
C.2.0
D.2.5
What is the value of x after the
following operation?
my_string = “I like lamp”
x = my_string[2]
A.I
B.L
C.K
D.like lamp
What is the output?
print(2 + 3)
A.2 + 3
B.2 + 3 = 5
C.5
D.Python throws an error
What Is the Output?
numerator = 4
denominator = 2
if denominator == 0:
print("Cannot divide by zero!")
else:
print( \
numerator, \
"/", \
denominator, \
"=", \
numerator / denominator \
)
A.
B.
Cannot divide by zero!
2.0
What Is the Output?
guess = 35
if guess < 100:
if guess > 50:
print("Do")
elif guess > 25:
print("Re")
else:
print("Mi")
else:
print("Fa")
A.
B.
C.
D.
Do
Re
Mi
Fa
What Is the Output?
guess = 25
if guess < 100:
if guess > 50:
print("Do")
elif guess > 25:
print("Re")
else:
print("Mi")
else:
print("Fa")
A.
B.
C.
D.
Do
Re
Mi
Fa
Quiz Question
The main difference between FOR and WHILE
loops is that we usually know the exact
number of iterations in a FOR loop.
A. True
B. False
Are these loops equivalent?
i = 0
while i <= 9:
print(i)
i = i + 1
---------------for i in range(11):
print i
A. Yes
B. No
Related documents