Unit 1: Setting up your Programming Environment; Variables, Expression and Statements - Practice Quiz

INT108 — Python Programming 50 Questions
0 Correct 0 Wrong 50 Left
0/50

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 3 does not have a print function
C. There is no difference
D. Python 2 uses parentheses for print, while Python 3 does not require them

2 What is the standard file extension for Python scripts?

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

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

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

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

A. print('Hello World')
B. echo '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. my-var
B. my var
C. _my_var
D. 2my_var

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

A. The program returns 0
B. A NameError occurs
C. The program returns None
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. Keywords must always be uppercase
B. 'Variable' and 'variable' are the same
C. 'Variable' and 'variable' are different identifiers
D. Variables must always be uppercase

10 Which of the following is a Python keyword?

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

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

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

12 What is the data type of the value 3.14?

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

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

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

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

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

15 What is a 'statement' in Python?

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

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

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

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

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

18 Which operator calculates the remainder of a division?

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

19 What is the result of 2 ** 3?

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

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

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

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

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

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 throws a TypeError
B. It concatenates the strings
C. It adds the ASCII values
D. It subtracts them

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

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

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

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

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

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

27 Which naming convention is recommended for Python variable names?

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

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

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

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

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

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

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

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

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

32 Why are comments important in programming?

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

33 What is the result of: 10 % 3?

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

34 Which of the following is NOT an assignment statement?

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

35 How do you represent a string literal in Python?

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

36 What identifies the values acted upon by an operator?

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

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

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

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

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

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

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

40 What is the binary operator for multiplication?

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

41 Which of the following is an illegal variable name?

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

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

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

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. language = 'Python'
C. 'Python' = language
D. set language 'Python'

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

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

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. Evaluation from left to right regardless
B. None
C. Addition
D. Multiplication

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

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

49 What does a SyntaxError generally indicate?

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

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

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