Quizz Python
Quizz Python
Quizz Python
When Python is running in the interactive mode and displaying the chevron prompt (>>>) - what
question is Python asking you?
1. What Python script would you like me to run?
2. Where would you like to navigate to?
3. What is the next machine language instruction to run?
4. What would you like to do?
Question 2
Python scripts (files) have names that end with:
1. .exe
2. .png
3. .doc
4. .py
Question 3
Which of these words is a reserved word in Python ?
1. while
2. payroll
3. pizza
4. make
Question 4
What is the proper way to say good-bye to Python?
1. #EXIT
2. // stop
3. while
4. quit()
Question 5
Which of the following is a comment in Python?
1. /* This is a test */
2. // This is a test
3. /// his is a test
4. # This is a test
Question 6
Which of the following is a bad Python variable name?
1. spam23
2. SPAM23
3. Spam
4. spam.23
Question 7
Which of the following is not a Python reserved word?
1. iterate
2. break
3. if
4. else
Question 8
Which of the following elements of a mathematical expression in Python is evaluated first?
1. Parenthesis ( )
2. Subtraction 3. Multiplication *
4. Addition +
5. Question 7
Question 9
What value be in the variable x when the following statement is executed
x = int(98.6)
1. 99
2. 100
3. 98
4. 6
Question 10
What does the Python raw_input() function do?
1. Pause the program and read data from the user
2. Connect to the network and retrieve a web page.
3. Take a screen shot from an area of the screen
4. Read the memory of the running program
Question 1
What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when
the if statement is true?
Underline all of the conditional code
Indent the line below the if statement
Start the statement with a "#" character
Begin the statement with a curly brace {
Question 2
Question 3
Question 4
When you have multiple lines in an if block, how do you indicate the end of the if block?
You capitalize the first letter of the line following the end of the if block
You omit the semicolon ; on the last line of the if block
You de-indent the next line past the if block to the same level of indent as the original if statement
You use a curly brace { after the last line of the if block
Question 5
You look at the following text:
if x == 6 :
print 'Is 6'
print 'Is Still 6'
print 'Third 6'
It looks perfect but Python is giving you an 'Indentation Error' on the second print statement. What is the most likely reason?
Python has reached its limit on the largest Python program that can be run
In order to make humans feel inadequate, Python randomly emits 'Indentation Errors' on perfectly good code - after about an hour the error will just
go away without any changes to your program
You have mixed tabs and spaces in the file
Python thinks 'Still' is a mis-spelled word in the string
Question 6
What is the Python reserved word that we use in two-way if tests to indicate the block of code that is to be executed if the logical test is false?
else
toggle
Question 7
Question 8
Question 9
'In the following code (numbers added) - which will be the last line to execute successfully?
(1) astr = 'Hello Bob'
(2) istr = int(astr)
(3) print 'First', istr
(4) astr = '123'
(5) istr = int(astr)
(6) print 'Second', istr
3
1
2
5
Question 10
It will be a random number depending on the operating system the program runs on
The istr variable will not have a value
-1
Question 1
Which Python keyword indicates the start of a function definition?
continue
return
sweet
def
Question 2
In Python, how do you indicate the end of the block of code that makes up the function?
You add a line that has at least 10 dashes
You put the "END" keyword in column 7 of the line which is to be the last line of the function
You put the colon character (:) in the first column of a line
You de-indent a line of code to the same indent level as the def keyword
Question 3
In Python what is the raw_input() feature best described as?
The central processing unit
A way to retrieve web pages over the network
A user-defined function
A built-in function
Question 4
There
Hello
thing
Hello
There
There
Question 5
Question 6
What will the following Python code print out?
def func(x) :
print x
func(10)
func(20)
x
x
x
10
x
20
10
20
def
x
func
func
Question 7
Which line of the following Python program is useless?
def stuff():
print 'Hello'
return
print 'World'
stuff()
def stuff():
stuff()
print 'World'
print 'Hello'
return
Question 8
Hola Michael
def
Hola
Bonjour
Hello
Michael
Hola
Bonjour
Hello
Question 9
What does the following Python code print out? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug so read carefully).
def addtwo(a, b):
added = a + b
return a
x = addtwo(2, 7)
print x
Traceback
9
2
14
Question 10