Unit 1: Introduction; Variables, Expressions and Statements - Practice Quiz

ECE181 — Introduction To Python 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the primary purpose of a programming language?

need for a programming language Easy
A. To store data permanently on disk
B. To design computer hardware circuits
C. To increase the speed of the CPU
D. To communicate instructions to a computer

2 Python is best described as which type of programming language?

introduction to python as a programming language Easy
A. A low-level assembly language
B. A markup language for web pages
C. A high-level, interpreted language
D. A hardware description language

3 Who is credited with creating the Python programming language?

introduction to python as a programming language Easy
A. Dennis Ritchie
B. Bjarne Stroustrup
C. Guido van Rossum
D. James Gosling

4 Which type of error occurs when Python code violates the rules of the language, such as a missing colon?

programming errors and debugging Easy
A. Runtime error
B. Logical error
C. Semantic error
D. Syntax error

5 What is the process of finding and fixing errors in a program called?

programming errors and debugging Easy
A. Formatting
B. Compiling
C. Executing
D. Debugging

6 Which of the following is a valid Python identifier?

identifiers Easy
A. _myVar
B. class
C. my-var
D. 2ndValue

7 Which statement about Python identifiers is true?

identifiers Easy
A. They may contain spaces
B. They can start with a digit
C. They are case-sensitive
D. They ignore uppercase letters

8 What is a variable in Python?

variables Easy
A. A type of loop structure
B. A fixed value that never changes
C. A named reference to a stored value
D. A built-in function name

9 What does the statement x = 5 do in Python?

assignment statements Easy
A. Prints the value 5
B. Compares x with 5
C. Checks if x equals 5
D. Assigns the value 5 to the variable x

10 Which of the following is an example of an expression in Python?

expressions Easy
A.
B. if x:
C. def foo():
D. while True:

11 By convention, how are named constants usually written in Python?

named constant Easy
A. In camelCase
B. With a leading digit
C. In all lowercase letters
D. In all uppercase letters

12 What will be the values of a and b after a, b = 1, 2?

simultaneous assignment Easy
A. a is 1 and b is 2
B. both a and b are 1
C. a is 2 and b is 1
D. both a and b are 2

13 Which single statement correctly swaps the values of x and y in Python?

simultaneous assignment Easy
A. x == y, y == x
B. swap(x, y)
C. x, y = y, x
D. x = y = x

14 Which of the following are the two Boolean values in Python?

boolean types Easy
A. Yes and No
B. True and False
C. 1 and 0 only
D. true and false

15 Which numeric data type represents whole numbers in Python?

numeric data types Easy
A. complex
B. float
C. int
D. str

16 What is the data type of the value 3.14 in Python?

numeric data types Easy
A. complex
B. float
C. int
D. bool

17 Which operator is used for exponentiation in Python?

operators Easy
A. %
B. **
C. //
D. ^

18 What is the result of the expression 2 + 3 * 4 in Python?

operator precedence and associativity Easy
A. 24
B. 14
C. 11
D. 20

19 What does the statement x += 3 mean in Python?

augmented assignment operators Easy
A. x = 3 - x
B. x = x * 3
C. x = 3
D. x = x + 3

20 What does the function int(4.9) return in Python?

type conversion and rounding Easy
A. 4
B. 5
C. 4.9
D. 0

21 What is the data type of the result of the expression 7 / 2 in Python 3?

numeric data types Medium
A. float
B. decimal
C. complex
D. int

22 What is the output of 17 % 5 in Python?

operators Medium
A. 2
B. 5
C. 12
D. 3

23 What is the value of the expression 2 + 3 * 4 ** 2?

operator precedence and associativity Medium
A. 50
B. 400
C. 80
D. 196

24 What does the expression 2 ** 3 ** 2 evaluate to in Python?

operator precedence and associativity Medium
A. 256
B. 64
C. 512
D. 128

25 After the code x = 10 followed by x //= 3, what is the value of x?

augmented assignment operators Medium
A. 1
B. 3
C. 3.33
D. 4

26 After executing a, b = 5, 10 and then a, b = b, a, what are the values of a and b?

simultaneous assignment Medium
A. a = 10, b = 5
B. a = 10, b = 10
C. a = 5, b = 10
D. a = 5, b = 5

27 What is the output of int(9.99) in Python?

type conversion and rounding Medium
A. 10
B. 9.99
C. 9
D. 9.0

28 What does round(2.5) return in Python 3?

type conversion and rounding Medium
A. 2.0
B. 3
C. 2
D. 2.5

29 What is the result of the expression True + True + False in Python?

boolean types Medium
A. 1
B. True
C. 2
D. TypeError

30 What is the output of bool(0.0) or bool("")?

boolean types Medium
A. True
B. 0.0
C. False
D. None

31 Which of the following is a valid Python identifier?

identifiers Medium
A. _total_2
B. total 2
C. total-2
D. 2total

32 Why does the statement class = 5 raise an error in Python?

identifiers Medium
A. integers cannot be assigned to names
B. class must be capitalized
C. the value must be a string
D. class is a reserved keyword

33 A program runs without crashing but produces an incorrect average. What type of error is this?

programming errors and debugging Medium
A. Syntax error
B. Runtime error
C. Indentation error
D. Logical error

34 Dividing by zero in x = 5 / 0 produces which kind of error?

programming errors and debugging Medium
A. Syntax error
B. Semantic error
C. Runtime error
D. Logical error

35 What is the value of the expression 10 - 4 - 2 in Python?

expressions Medium
A. 6
B. 4
C. 0
D. 8

36 What happens when the following runs: x = 5 then x = x + "3"?

assignment statements Medium
A. x becomes "53"
B. x becomes 53
C. TypeError is raised
D. x becomes 8

37 By convention, how should a named constant like the value of Pi be written in Python?

named constant Medium
A. pi
B. pi
C. Pi
D. PI

38 After a = 3 and b = a and then a = 7, what is the value of b?

variables Medium
A. None
B. 3
C. 7
D. 10

39 Why do we use high-level programming languages instead of machine code directly?

need for a programming language Medium
A. They use only binary digits
B. They run faster than machine code
C. They are easier for humans to read and write
D. They require no translation to execute

40 Which statement best describes Python as a programming language?

introduction to python as a programming language Medium
A. It is a compiled, statically typed language
B. It requires variable types to be declared
C. It is an interpreted, dynamically typed language
D. It converts code directly to machine code

41 What is the result of evaluating 2 ** 3 ** 2 in Python?

operator precedence and associativity Hard
A. 512
B. 64
C. 81
D. 36

42 What does 0.1 + 0.2 == 0.3 evaluate to in Python, and why?

numeric data types Hard
A. True, after automatic rounding
B. False, because == is invalid for floats
C. False, due to floating-point representation error
D. True, since decimals are exact

43 What is the output of round(2.5) + round(3.5)?

type conversion and rounding Hard
A. 5
B. 8
C. 7
D. 6

44 After executing a, b = 1, 2 then a, b = b, a + b, what are the values of a and b?

simultaneous assignment Hard
A. a = 3, b = 2
B. a = 2, b = 3
C. a = 1, b = 3
D. a = 2, b = 4

45 What is the result of True + True + False in Python?

boolean types Hard
A. TypeError
B. 1
C. True
D. 2

46 What is the value of -7 // 2 in Python?

operators Hard
A. -3.5
B. 3
C. -4
D. -3

47 What does -7 % 3 evaluate to in Python?

operators Hard
A. -1
B. 1
C. 2
D. -2

48 What is the output of 2 + 3 * 4 ** 2 // 5 - 1?

expressions Hard
A. 9
B. 10
C. 8
D. 11

49 Given x = 5, what is the value of x after x //= 2; x **= 2; x -= 1?

augmented assignment operators Hard
A. 8
B. 3
C. 4
D. 5

50 Which of the following is a valid Python identifier?

identifiers Hard
A. total-sum
B. _total2
C. 2total
D. class

51 What is the output of int("10", 2) + int("10")?

type conversion and rounding Hard
A. 4
B. 22
C. 12
D. 20

52 What is the type and value of 5 / 5 in Python 3?

numeric data types Hard
A. float, 1
B. float, 1.0
C. int, 1
D. int, 1.0

53 A program runs without crashing but produces incorrect output. What type of error is this?

programming errors and debugging Hard
A. Runtime exception
B. Indentation error
C. Logical (semantic) error
D. Syntax error

54 What is the result of not True == False in Python?

expressions Hard
A. TypeError
B. False
C. None
D. True

55 What does 5 & 3 | 2 evaluate to?

operators Hard
A. 3
B. 7
C. 1
D. 2

56 After x = y = [1, 2]; x.append(3), what is the value of y?

assignment statements Hard
A. [1, 2]
B. [1, 2, 3]
C. NameError
D. [3]

57 What is true about a named constant like PI = 3.14159 in Python?

named constant Hard
A. It must be declared with a const keyword
B. It cannot be reassigned once defined
C. It is a convention only; Python does not enforce immutability
D. It is stored in read-only memory automatically

58 What is the output of round(3.14159, 2) and its type?

type conversion and rounding Hard
A. 3.15, float
B. 3.14, float
C. 3, int
D. 3.14, str

59 What does the expression 0 or "" or [] or "Python" return?

boolean types Hard
A. []
B. "Python"
C. True
D. 0

60 Which statement best describes Python's execution model?

introduction to python as a programming language Hard
A. Source code is compiled directly to native machine code before running
B. Source code is executed line-by-line with no intermediate representation
C. Source code is translated to assembly and linked into an executable
D. Source code is compiled to bytecode, then run by an interpreter (virtual machine)