COMP560 W1 Quiz

  1. What is printed by the following code snippet?

A) Good Morning Class !

2. An integrated development environment bundles tools for programming into a unified application. What kinds of tools are usually included?
A) An editor and an interpreter
 3. A computer program is a sequence of:
A) instructions and decisions.
 4. Which of the following hardware devices is NOT considered an input device?
A) Monitor
 5. To use or call a function, you need to specify:
A) the function name and its arguments
 6. What is printed by the following code snippet?

A) Nothing, an error is produced indicating that Hello is not defined

7. 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

A) To find the highest among 15 numbers

8. What is wrong with the following code snippet?

print("Hello")
   print("World!")

A) The second line should not be indented
9. What is the difference between an editor and an interpreter?
A) An editor allows program files to be entered and modified; an interpreter reads and executes program files

10. The following pseudocode calculates the total purchase price for an item including sales tax, what is the missing last line?

Start by setting the total cost to zero.
Ask the user for the item cost.
Ask the user for the tax rate.
Set the item tax to item cost times tax rate. 
 _________________________________

A) Set the total cost to the item cost plus the tax.
11. The programmer, not the compiler, is responsible for testing a program to identify what?

A) Logic errors
12. By entering the command python3, the program runs in which mode?

A) interactive mode
13. Which of the following statements is NOT correct?
A) Pseudocode should be properly formatted.
14. Which parts of the computer store program code?
A) Secondary storage
15. What is it called when you describe the steps that are necessary for finding a solution to a problem in programming?

A) algorithm
16. Although the following code statement is valid, print(10/0), what will happen when this code is executed?

A) The error message ZeroDivisionError: int division or modulo by zero is displayed

17. Consider the following pseudocode. What does it produce?

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

A) 1 1 2 3 5 8 13 21 34 55 89
18. What is another name for a compile-time error?
A) Syntax error
19. Which of the following is NOT an example of an algorithm?

A) A grocery list
20. Which type of error is usually the most difficult to locate in your program?

A) Logic Error
21. What is wrong with the following code snippet

num1 = 10
num2 = 20
num3 = 30
total = Num1 + Num2 + Num3

A) Python is case sensitive so Num1Num2, and Num3 are undefined

22. Imagine that you are planning to buy a new cell phone. After doing some research, you have determined that there are two different cell phones that will meet your needs. These cell phones have different purchase prices and each mobile service provider charges a different rate for each minute that the cell phone is used. In order to determine which cell phone is the better buy, you need to develop an algorithm to calculate the total cost of purchasing and using each cell phone. Which of the following options lists all the inputs needed for this algorithm?

A) The cost of each cell phone, the rate per minute for each cell phone, and the number of minutes you would use the cell phone

23. The Central Processing Unit is primarily responsible for:
A) performing program control and data processing.

24. What is the correct sequence of steps invoked by the Python Interpreter:
A) source code -> compiler -> byte code -> virtual machine

25. Which of the following refers to a collection of programs that a computer executes?
A) Software
26. Computers are machines that:
A) execute programs.
27. Which of the following statements is most correct?
A) Computer programs are comprised of a large number of simple instructions.

28. What is printed by the following code snippet?

print("The answer is", 25 + 84)

A) The answer is 109

29. Which of the following items is NOT considered hardware:
A) a program.
30. What is printed by the following code snippet?

print(25 + 84)

A) 109

31. Which of the following pseudocode statements represents a decision?
A) if total cost > 15
32. A Python interpreter is:
A) a piece of software
33. When the computer begins to run a program,
A) the program is moved from secondary storage to memory.

34. In order to run Python programs, the computer needs to have software called a(n)?
A) interpreter
35. Which of the following pseudocode statements represents a repetition statement?
A) while the balance is > 0
36. Which of the following is not a benefit of the Python programming language compared to other popular programming languages like Java, C and C++?

A) Python programs run more quickly
37. What reads Python programs and executes the program instructions?
A) interpreter
38. The Python compiler reads the file containing your source code and converts it to:
A) byte code
39. Computers store both data and programs not currently running in:
A) Secondary storage.
40. A collection of programming instructions that carry out a particular task is called a:
A) function
41. When a function is called, the values placed in parentheses are referred to as:
A) arguments
42. Which of the following is considered a string in Python?
A) “Today is Wednesday”

43. Which of the following code segments will display Hello World! when it is run?
A) print(“Hello”, “World!”)

44. What is printed by the following code snippet?

print("25 + 84")

A) 25 + 84

45. What is printed by the following code snippet?

print("The answers are:", 4 + 3 * 2, 7 * 5 - 24)

A) The answers are: 10 11

46. Consider the following pseudocode. What does it produce?

Create a list of consecutive integers from two to n (2, 3, 4, ..., n).
Initially, let p equal 2.
Repeat the following steps until p is greater than n:
    Remove all of the multiples of p less than or equal to n from the list. 
    If the list contains a number greater than p
        Find the first number remaining in the list greater than p.
        Replace p with this number.
    Otherwise set p equal to n + 1

A) All prime numbers up to n
47. What extension is used for Python files?
A) .py
48. A sequence of steps that is unambiguous, executable, and terminating is called:
A) an algorithm

49. What is the purpose of a comment?
A) A comment provides information to the programmer
50. What are two of the most important benefits of the Python language?
A) Ease of use and portability
51. Which of the following hardware devices is NOT considered an output device?
A) Microphone
52. A sequence of characters enclosed in quotes is called:
A) a string

53. What part of the computer carries out arithmetic operations, such as addition, subtraction, multiplication and division?
A) CPU
54. High-level programming languages were created to:
A) Make programming less error-prone and less tedious
55. Which line in the following program is a comment line?

1:  print("Your lucky number is...")
2:  lucky = 7
3:  # Display the lucky number
4:  print(lucky)

A) Line number 3
 

Leave a Reply

Your email address will not be published. Required fields are marked *