Unit 1 - Practice Quiz

INT108

1 Which of the following is a major difference between Python 2 and Python 3 regarding the print statement?

A. Python 3 uses parentheses for print, while Python 2 does not require them
B. Python 2 uses parentheses for print, while Python 3 does not require them
C. There is no difference
D. Python 3 does not have a print function

2 What is the standard file extension for Python scripts?

A. .pt
B. .py
C. .pyt
D. .pn

3 Which command is typically used in the Windows Command Prompt to run a Python file named 'script.py'?

A. run script.py
B. execute script.py
C. python script.py
D. go script.py

4 What is the correct syntax to output 'Hello World' in Python 3?

A. echo 'Hello World'
B. print('Hello World')
C. console.log('Hello World')
D. System.out.println('Hello World')

5 Which symbol indicates that the Python interpreter is running in interactive mode?

A. >>>
B. ###
C. $$$
D. ---

6 Which of the following is a valid variable name in Python?

A. 2my_var
B. my-var
C. _my_var
D. my var

7 What happens if you try to use a variable that has not been defined?

A. The program returns 0
B. The program returns None
C. A NameError occurs
D. A TypeError occurs

8 Which operator is used to assign a value to a variable?

A. ==
B. ->
C. =
D. :

9 Python is a case-sensitive language. What does this mean?

A. 'Variable' and 'variable' are the same
B. 'Variable' and 'variable' are different identifiers
C. Variables must always be uppercase
D. Keywords must always be uppercase

10 Which of the following is a Python keyword?

A. variable
B. yield
C. print
D. integer

11 What function is used to check the data type of a value?

A. check()
B. typeof()
C. type()
D. class()

12 What is the data type of the value 3.14?

A. int
B. float
C. str
D. bool

13 What is the data type of the value '10'?

A. int
B. float
C. str
D. bool

14 Which of the following represents a Boolean value in Python?

A. true
B. TRUE
C. True
D. 1.0

15 What is a 'statement' in Python?

A. A unit of code that the Python interpreter can execute
B. A comment line
C. A math equation only
D. A syntax error

16 Which of the following is an example of an expression?

A. x = 5
B. import os
C. 5 + 10
D. if x > 5:

17 What is the result of the floor division operation: 7 // 2?

A. 3.5
B. 3
C. 4
D. 2

18 Which operator calculates the remainder of a division?

A. /
B. //
C. %
D. #

19 What is the result of 2 ** 3?

A. 6
B. 5
C. 8
D. 9

20 What is the output of the following code: print(10 / 2)?

A. 5
B. 5.0
C. 2
D. 10

21 Following the order of operations (PEMDAS), what is the result of 2 + 3 * 4?

A. 20
B. 14
C. 24
D. 10

22 Which character starts a single-line comment in Python?

A. //
B. /*
C. #
D. --

23 What happens when you use the '+' operator on two strings?

A. It adds the ASCII values
B. It concatenates the strings
C. It throws a TypeError
D. It subtracts them

24 What happens when you use the '' operator on a string and an integer (e.g., 'Hi' 3)?

A. TypeError
B. It repeats the string 3 times
C. It creates a list
D. It adds the number to the string

25 What is the result of executing: print('5' + 5)?

A. 10
B. 55
C. TypeError
D. NaN

26 Variables in Python are 'dynamically typed'. What does this mean?

A. You must declare the type before assigning a value
B. A variable can hold different types of values at different times
C. Variables cannot change values
D. Variables are strictly typed like C++

27 Which naming convention is recommended for Python variable names?

A. camelCase
B. PascalCase
C. snake_case
D. kebab-case

28 What is the associativity of the exponentiation operator (**) in Python?

A. Left-to-right
B. Right-to-left
C. Random
D. Center

29 What is 'Composition' in the context of Python expressions?

A. Writing comments
B. Combining simple expressions and statements into compound ones
C. Installing Python packages
D. Compiling code to C

30 Which of the following variable names leads to a SyntaxError?

A. class
B. clazz
C. klass
D. Class_Name

31 What does the function input() return by default?

A. int
B. float
C. str
D. list

32 Why are comments important in programming?

A. They make the code run faster
B. They explain what the code does to humans
C. They are required by the compiler
D. They encrypt the code

33 What is the result of: 10 % 3?

A. 3.33
B. 3
C. 1
D. 10

34 Which of the following is NOT an assignment statement?

A. n = 17
B. pi = 3.14159
C. message = 'Hello'
D. 17 + 3

35 How do you represent a string literal in Python?

A. Only single quotes
B. Only double quotes
C. Either single or double quotes
D. Parentheses

36 What identifies the values acted upon by an operator?

A. Keywords
B. Operands
C. Comments
D. Functions

37 If x = 10 and y = 20, what is the result of: print(x, y)?

A. 1020
B. 30
C. 10 20
D. x y

38 Which of the following creates a multi-line string or comment?

A. #
B. //
C. ''' (triple quotes)
D. <!-- -->

39 What error is raised if you write: print 'Hello' in Python 3?

A. NameError
B. SyntaxError
C. TypeError
D. ValueError

40 What is the binary operator for multiplication?

A. x
B. *
C. mul
D. #

41 Which of the following is an illegal variable name?

A. catch_22
B. 22_catch
C. _catch22
D. CATCH22

42 If you define variable x = 10 and then x = 'Hello', what happens?

A. Error: Type mismatch
B. x now holds the string 'Hello'
C. x keeps the value 10
D. The program crashes

43 The term 'IDLE' in Python stands for:

A. Integrated Development and Learning Environment
B. Internal Developer Loop Engine
C. Interactive Design Language Environment
D. Integrated Debugging Line Editor

44 Which of the following statements assigns the string 'Python' to the variable named language?

A. language == 'Python'
B. 'Python' = language
C. language = 'Python'
D. set language 'Python'

45 What will be the output of: print(3 * '7')?

A. 21
B. 777
C. Syntax Error
D. 37

46 Which character is used to separate two statements on a single line?

A. ,
B. ;
C. :
D. /

47 In the expression (5 + 2) * 3, which operation happens first?

A. Multiplication
B. Addition
C. Evaluation from left to right regardless
D. None

48 What will the following code output? print(type('5.5'))

A. <class 'int'>
B. <class 'float'>
C. <class 'str'>
D. <class 'bool'>

49 What does a SyntaxError generally indicate?

A. The logic of the program is wrong
B. The code violates the grammatical rules of Python
C. The variable name is not found
D. There is a division by zero

50 When you install Python on Windows, what needs to be added to the PATH variable to run python from any command prompt?

A. The browser history
B. The directory where python.exe is located
C. The My Documents folder
D. Nothing, it works automatically