Chapter 1 - Sample Questions
Chapter 1 - Sample Questions
num1 = 10
num2 = 20
num3 = 30
total = Num1 + Num2 + Num3
1. Nothing, the variable total will be the sum of the three numbers
2. Python is case sensitive so Num1, Num2, and Num3 are undefined
3. total must be initialized to zero first
4. The numbers should be 10.0, 20.0 and 30.0
15. An integrated development environment bundles tools for programming into a unified
application. What kinds of tools are usually included?
1. A web browser
2. An editor and an interpreter
3. Presentation tools
4. Source files and bytecode files
16. What is the difference between an editor and an interpreter?
1. An editor allows program files to be entered and modified; an interpreter reads
and executes program files
2. An editor allows program files to be entered and modified; an interpreter produces
an indexed database of terms and keywords
3. An editor allows program files to be entered and modified; an interpreter produces
an organized list of files
4. An editor converts program files into an executable program; an interpreter allows
program files to be entered and modified
17. What reads Python programs and executes the program instructions?
1. editor
2. CPU
3. compiler
4. interpreter
18. What extension is used for Python files?
1. .Python
2. .py
3. .dat
4. .txt
19. By entering the command python3, the program runs in which mode?
1. interactive mode
2. print mode
3. command mode
4. backup mode
20. The Python compiler reads the file containing your source code and converts it to:
1. machine code
2. assembly code
3. byte code
4. virtual machine code
21. What is the correct sequence of steps invoked by the Python Interpreter:
1. source code -> virtual machine -> byte code -> compiler
2. source code -> compiler -> byte code -> virtual machine
3. compiler -> source code -> virtual machine -> byte code
4. byte code -> virtual machine -> source code -> compiler
22. Which line in the following program is a comment line?
1. Line number 1
2. Line number 2
3. Line number 3
4. Line number 4
23. What is the purpose of a comment?
1. A comment provides information to the virtual machine
2. A comment provides information to the compiler
3. A comment provides information to the programmer
4. A comment provides information to the user running the program
24. A collection of programming instructions that carry out a particular task is called a:
1. program
2. compiler
3. function
4. comment
25. To use or call a function, you need to specify:
1. the function name and its arguments
2. the function name only
3. the function name and at least one argument
4. the function name and a comment describing its use
26. A sequence of characters enclosed in quotes is called:
1. a string
2. a list
3. a function
4. an argument
27. Which of the following is considered a string in Python?
1. Today is Wednesday
2. "Today is Wednesday"
3. # Today is Wednesday #
4. Today_is_Wednesday
28. What is wrong with the following code snippet?
print("Hello")
print("World!")
print(25 + 84)
1. 2584
2. 109
3. 25 + 84
4. Nothing, this code snipped causes a compile time error
30. What is printed by the following code snippet?
print("25 + 84")
1. 2584
2. 109
3. 25 + 84
4. Nothing, this code snipped causes a compile time error
33. What is printed by the following code snippet?
print(Hello)
1. GoodMorningClass!
2. Good Morning Class!
3. Good Morning Class !
4. nothing, this code produces a syntax error
35. What is another name for a compile-time error?
1. Logic error
2. Semantic error
3. Syntax error
4. Lexicographic error
36. Although the following code statement is valid, print(10/0), what will happen when
this code is executed?
1. The program prints 0
2. The error message ZeroDivisionError: int division or modulo by zero
is displayed
3. The program runs, but nothing is printed
4. The error message SyntaxError: EOL while scanning string literal
37. The programmer, not the compiler, is responsible for testing a program to identify what?
1. Undefined symbols
2. Syntax errors
3. Logic errors
4. Out-of-memory errors
38. What is it called when you describe the steps that are necessary for finding a solution to a
problem in programming?
1. algorithm
2. compile
3. interpret
4. code
39. The following pseudocode calculates the total purchase price for an item including sales
tax, what is the missing last line?
1. Set the total cost to the item cost plus the tax rate.
2. Set the total cost to the item cost times the tax.
3. Set the total cost to the item cost plus the tax.
4. Set the total cost to the item tax.
40. What is the purpose of the following algorithm, written in pseudocode?
num = 0
Repeat the following steps 15 times
Ask user for next number
If userNum > num
num = userNum
Print num
Set a = 0
Set b = 0
Set c = 1
Set d = 1
Report the value of d
Repeat until a equals 10
Set d = b + c
Set b = c
Set c = d
Add 1 to a
Report the value of d
1. 1 1 2 3 5 8 13 21 34 55 89
2. 1 1 3 5 7 9 11 13 15 17 19 21
3. 1 1 3 6 9 12 15 18 21 24 27 30
4. 1 2 3 4 5 6 7 8 9 10 11
50. A sequence of steps that is unambiguous, executable, and terminating is called:
1. a logarithm
2. a programming task
3. an algorithm
4. pseudocode
51. Which of the follow statements is most correct?
1. Computer programs are comprised of a large number of simple instructions.
2. Computer programs are comprised of a large number of sophisticated instructions.
3. Computer programs are comprised of a small number of simple instructions.
4. Computer programs are comprised of a small number of sophisticated
instructions.
52. Which of the following is not a benefit of the Python programming language compared
to other popular programming languages like Java, C and C++?
1. Python encourages experimentation and rapid turn around
2. Python has a cleaner syntax
3. Python is easier to use
4. Python programs run more quickly
53. Which of the following code segments will display Hello World! when it is run?
1. print(Hello "," World"!")
2. print("Hello", "World!")
3. print("Hello", "World", "!")
4. print("Hello", ",", "World", "!")
54. When a function is called, the values placed in parentheses are referred to as:
1. arguments
2. keywords
3. operators
4. statements
55. Which type of error is usually the most difficult to locate in your program?
1. Indentation Error
2. Logic Error
3. Syntax Error
4. Zero Division Error