Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 1 MCQsIntroduction; Variables, Expressions and Statements
Question 1 of 60 · need for a programming language · Easy
What is the primary purpose of a programming language?
Not quite. Try another option.
Answer: To communicate instructions to a computer
A programming language provides a structured way for humans to write instructions that a computer can understand and execute.
Question 2 of 60 · introduction to python as a programming language · Easy
Python is best described as which type of programming language?
Not quite. Try another option.
Answer: A high-level, interpreted language
Python is a high-level language that is executed by an interpreter, making it easy to read and write.
Question 3 of 60 · introduction to python as a programming language · Easy
Who is credited with creating the Python programming language?
Not quite. Try another option.
Answer: Guido van Rossum
Python was created by Guido van Rossum and first released in 1991.
Question 4 of 60 · programming errors and debugging · Easy
Which type of error occurs when Python code violates the rules of the language, such as a missing colon?
Not quite. Try another option.
Answer: Syntax error
A syntax error occurs when code does not follow the grammatical rules of the language and prevents it from running.
Question 5 of 60 · programming errors and debugging · Easy
What is the process of finding and fixing errors in a program called?
Not quite. Try another option.
Answer: Debugging
Debugging is the systematic process of locating and correcting errors (bugs) in a program.
Question 6 of 60 · identifiers · Easy
Which of the following is a valid Python identifier?
Not quite. Try another option.
Answer: _myVar
Identifiers may begin with a letter or underscore, cannot start with a digit, cannot contain hyphens, and cannot be reserved keywords like class.
Question 7 of 60 · identifiers · Easy
Which statement about Python identifiers is true?
Not quite. Try another option.
Answer: They are case-sensitive
Python identifiers are case-sensitive, so age and Age are treated as two different names.
Question 8 of 60 · variables · Easy
What is a variable in Python?
Not quite. Try another option.
Answer: A named reference to a stored value
A variable is a name that refers to a value stored in memory, and its value can be changed during execution.
Question 9 of 60 · assignment statements · Easy
What does the statement x = 5 do in Python?
Not quite. Try another option.
Answer: Assigns the value 5 to the variable x
The single equals sign = is the assignment operator, which stores the value 5 in the variable x.
Question 10 of 60 · expressions · Easy
Which of the following is an example of an expression in Python?
Not quite. Try another option.
Answer:
An expression is a combination of values and operators that evaluates to a result, such as .
Question 11 of 60 · named constant · Easy
By convention, how are named constants usually written in Python?
Not quite. Try another option.
Answer: In all uppercase letters
Python has no true constants, but by convention constant names are written in uppercase, such as PI = 3.14159.
Question 12 of 60 · simultaneous assignment · Easy
What will be the values of a and b after a, b = 1, 2?
Not quite. Try another option.
Answer: a is 1 and b is 2
Simultaneous assignment assigns values in order, so a gets 1 and b gets 2.
Question 13 of 60 · simultaneous assignment · Easy
Which single statement correctly swaps the values of x and y in Python?
Not quite. Try another option.
Answer: x, y = y, x
Simultaneous assignment x, y = y, x swaps the two values without needing a temporary variable.
Question 14 of 60 · boolean types · Easy
Which of the following are the two Boolean values in Python?
Not quite. Try another option.
Answer: True and False
Python's Boolean type has exactly two values, True and False, both written with capital first letters.
Question 15 of 60 · numeric data types · Easy
Which numeric data type represents whole numbers in Python?
Not quite. Try another option.
Answer: int
The int type represents whole numbers, while float is used for numbers with decimal points.
Question 16 of 60 · numeric data types · Easy
What is the data type of the value 3.14 in Python?
Not quite. Try another option.
Answer: float
Numbers with a decimal point, like 3.14, are of the float data type in Python.
Question 17 of 60 · operators · Easy
Which operator is used for exponentiation in Python?
Not quite. Try another option.
Answer: **
The ** operator raises a number to a power, so 2 ** 3 equals 8.
Question 18 of 60 · operator precedence and associativity · Easy
What is the result of the expression 2 + 3 * 4 in Python?
Not quite. Try another option.
Answer: 14
Multiplication has higher precedence than addition, so 3 * 4 is evaluated first, giving 2 + 12 = 14.
Question 19 of 60 · augmented assignment operators · Easy
What does the statement x += 3 mean in Python?
Not quite. Try another option.
Answer: x = x + 3
The augmented assignment x += 3 is shorthand for x = x + 3.
Question 20 of 60 · type conversion and rounding · Easy
What does the function int(4.9) return in Python?
Not quite. Try another option.
Answer: 4
Converting a float to an int with int() truncates the decimal part, so int(4.9) returns 4.
Question 21 of 60 · numeric data types · Medium
What is the data type of the result of the expression 7 / 2 in Python 3?
Not quite. Try another option.
Answer: float
In Python 3, the / operator always performs true division and returns a float. So 7 / 2 gives 3.5, which is of type float.
Question 22 of 60 · operators · Medium
What is the output of 17 % 5 in Python?
Not quite. Try another option.
Answer: 2
The % operator returns the remainder of division. Since , the remainder is 2.
Question 23 of 60 · operator precedence and associativity · Medium
What is the value of the expression 2 + 3 * 4 ** 2?
Not quite. Try another option.
Answer: 50
Exponentiation has highest precedence: . Then multiplication: . Finally addition: .
Question 24 of 60 · operator precedence and associativity · Medium
What does the expression 2 ** 3 ** 2 evaluate to in Python?
Not quite. Try another option.
Answer: 512
The ** operator is right-associative, so it evaluates as 2 ** (3 ** 2) = 2 ** 9 = 512, not (2 ** 3) ** 2 = 64.
Question 25 of 60 · augmented assignment operators · Medium
After the code x = 10 followed by x //= 3, what is the value of x?
Not quite. Try another option.
Answer: 3
x //= 3 is equivalent to x = x // 3. Floor division of 10 // 3 gives 3 (the integer quotient).
Question 26 of 60 · simultaneous assignment · Medium
After executing a, b = 5, 10 and then a, b = b, a, what are the values of a and b?
Not quite. Try another option.
Answer: a = 10, b = 5
Simultaneous assignment evaluates the right-hand side first as a tuple (10, 5), then unpacks it. This swaps the values so a = 10 and b = 5.
Question 27 of 60 · type conversion and rounding · Medium
What is the output of int(9.99) in Python?
Not quite. Try another option.
Answer: 9
The int() function truncates the decimal part toward zero rather than rounding. So int(9.99) returns 9, not 10.
Question 28 of 60 · type conversion and rounding · Medium
What does round(2.5) return in Python 3?
Not quite. Try another option.
Answer: 2
Python 3 uses banker's rounding (round half to even). Since 2 is even, round(2.5) returns 2, not 3.
Question 29 of 60 · boolean types · Medium
What is the result of the expression True + True + False in Python?
Not quite. Try another option.
Answer: 2
In Python, True equals 1 and False equals 0 when used in arithmetic. So 1 + 1 + 0 = 2.
Question 30 of 60 · boolean types · Medium
What is the output of bool(0.0) or bool("")?
Not quite. Try another option.
Answer: False
Both 0.0 and an empty string "" are falsy, so bool(0.0) is False and bool("") is False. False or False gives False.
Question 31 of 60 · identifiers · Medium
Which of the following is a valid Python identifier?
Not quite. Try another option.
Answer: _total_2
Identifiers may begin with a letter or underscore and contain letters, digits, and underscores. _total_2 is valid; the others start with a digit or contain a hyphen or space.
Question 32 of 60 · identifiers · Medium
Why does the statement class = 5 raise an error in Python?
Not quite. Try another option.
Answer: class is a reserved keyword
class is a reserved keyword in Python used to define classes, so it cannot be used as a variable name. This causes a SyntaxError.
Question 33 of 60 · programming errors and debugging · Medium
A program runs without crashing but produces an incorrect average. What type of error is this?
Not quite. Try another option.
Answer: Logical error
A logical error occurs when the program runs successfully but produces incorrect results due to flawed logic. Syntax and runtime errors would stop execution.
Question 34 of 60 · programming errors and debugging · Medium
Dividing by zero in x = 5 / 0 produces which kind of error?
Not quite. Try another option.
Answer: Runtime error
The code is syntactically valid but fails during execution, raising a ZeroDivisionError. Errors detected while the program runs are runtime errors.
Question 35 of 60 · expressions · Medium
What is the value of the expression 10 - 4 - 2 in Python?
Not quite. Try another option.
Answer: 4
The subtraction operator is left-associative, so it evaluates as (10 - 4) - 2 = 6 - 2 = 4.
Question 36 of 60 · assignment statements · Medium
What happens when the following runs: x = 5 then x = x + "3"?
Not quite. Try another option.
Answer: TypeError is raised
You cannot add an integer and a string directly in Python. 5 + "3" raises a TypeError because operand types are incompatible.
Question 37 of 60 · named constant · Medium
By convention, how should a named constant like the value of Pi be written in Python?
Not quite. Try another option.
Answer: PI
Python has no true constants, but the naming convention (PEP 8) is to write constants in all uppercase letters, such as PI = 3.14159.
Question 38 of 60 · variables · Medium
After a = 3 and b = a and then a = 7, what is the value of b?
Not quite. Try another option.
Answer: 3
b = a binds b to the value 3. Reassigning a to 7 does not affect b, since integers are immutable and b still refers to 3.
Question 39 of 60 · need for a programming language · Medium
Why do we use high-level programming languages instead of machine code directly?
Not quite. Try another option.
Answer: They are easier for humans to read and write
High-level languages use human-readable syntax that is easier to write and maintain. They must still be translated into machine code before execution.
Question 40 of 60 · introduction to python as a programming language · Medium
Which statement best describes Python as a programming language?
Not quite. Try another option.
Answer: It is an interpreted, dynamically typed language
Python is interpreted (executed line by line by the interpreter) and dynamically typed (variable types are determined at runtime without explicit declaration).
Question 41 of 60 · operator precedence and associativity · Hard
What is the result of evaluating 2 ** 3 ** 2 in Python?
Not quite. Try another option.
Answer: 512
The ** operator is right-associative, so the expression evaluates as , not .
Question 42 of 60 · numeric data types · Hard
What does 0.1 + 0.2 == 0.3 evaluate to in Python, and why?
Not quite. Try another option.
Answer: False, due to floating-point representation error
Floats use binary IEEE-754 representation, so 0.1 + 0.2 yields 0.30000000000000004, which is not exactly equal to 0.3.
Question 43 of 60 · type conversion and rounding · Hard
What is the output of round(2.5) + round(3.5)?
Not quite. Try another option.
Answer: 6
Python uses banker's rounding (round-half-to-even). round(2.5) is 2 and round(3.5) is 4, so the sum is 6.
Question 44 of 60 · simultaneous assignment · Hard
After executing a, b = 1, 2 then a, b = b, a + b, what are the values of a and b?
Not quite. Try another option.
Answer: a = 2, b = 3
The right-hand side b, a + b is evaluated first using old values: b = 2 and a + b = 1 + 2 = 3. Then a becomes 2 and b becomes 3.
Question 45 of 60 · boolean types · Hard
What is the result of True + True + False in Python?
Not quite. Try another option.
Answer: 2
In Python, bool is a subclass of int, so True equals 1 and False equals 0. Thus 1 + 1 + 0 = 2.
Question 46 of 60 · operators · Hard
What is the value of -7 // 2 in Python?
Not quite. Try another option.
Answer: -4
Floor division rounds toward negative infinity. , and the floor of is .
Question 47 of 60 · operators · Hard
What does -7 % 3 evaluate to in Python?
Not quite. Try another option.
Answer: 2
In Python the result of % has the same sign as the divisor. Since , the remainder is 2.
Question 48 of 60 · expressions · Hard
What is the output of 2 + 3 * 4 ** 2 // 5 - 1?
Not quite. Try another option.
Answer: 10
By precedence: 4 ** 2 = 16, then 3 * 16 = 48, then 48 // 5 = 9, then 2 + 9 - 1 = 10.
Question 49 of 60 · augmented assignment operators · Hard
Given x = 5, what is the value of x after x //= 2; x **= 2; x -= 1?
Not quite. Try another option.
Answer: 3
x //= 2 gives 2, then x **= 2 gives 4, then x -= 1 gives 3.
Question 50 of 60 · identifiers · Hard
Which of the following is a valid Python identifier?
Not quite. Try another option.
Answer: _total2
Identifiers may start with a letter or underscore and contain letters, digits, and underscores. 2total starts with a digit, total-sum uses a hyphen, and class is a reserved keyword.
Question 51 of 60 · type conversion and rounding · Hard
What is the output of int("10", 2) + int("10")?
Not quite. Try another option.
Answer: 12
int("10", 2) interprets "10" as binary, giving 2. int("10") gives 10. So 2 + 10 = 12.
Question 52 of 60 · numeric data types · Hard
What is the type and value of 5 / 5 in Python 3?
Not quite. Try another option.
Answer: float, 1.0
The / operator always performs true division and returns a float, so 5 / 5 yields 1.0 of type float.
Question 53 of 60 · programming errors and debugging · Hard
A program runs without crashing but produces incorrect output. What type of error is this?
Not quite. Try another option.
Answer: Logical (semantic) error
Logical errors do not stop execution but cause incorrect results due to flawed logic. Syntax and runtime errors would prevent normal execution or raise exceptions.
Question 54 of 60 · expressions · Hard
What is the result of not True == False in Python?
Not quite. Try another option.
Answer: True
Comparison == has higher precedence than not. So it evaluates as not (True == False) = not False = True.
Question 55 of 60 · operators · Hard
What does 5 & 3 | 2 evaluate to?
Not quite. Try another option.
Answer: 3
Bitwise & has higher precedence than |. 5 & 3 = 1 (binary 101 & 011 = 001), then 1 | 2 = 3 (001 | 010 = 011).
Question 56 of 60 · assignment statements · Hard
After x = y = [1, 2]; x.append(3), what is the value of y?
Not quite. Try another option.
Answer: [1, 2, 3]
Chained assignment makes x and y reference the same list object. Appending via x mutates the shared list, so y is also [1, 2, 3].
Question 57 of 60 · named constant · Hard
What is true about a named constant like PI = 3.14159 in Python?
Not quite. Try another option.
Answer: It is a convention only; Python does not enforce immutability
Python has no built-in constant enforcement. Uppercase naming signals intent to other programmers, but the value can still be reassigned.
Question 58 of 60 · type conversion and rounding · Hard
What is the output of round(3.14159, 2) and its type?
Not quite. Try another option.
Answer: 3.14, float
round with a specified number of digits returns a float. Rounding 3.14159 to 2 decimals gives 3.14.
Question 59 of 60 · boolean types · Hard
What does the expression 0 or "" or [] or "Python" return?
Not quite. Try another option.
Answer: "Python"
The or operator returns the first truthy operand. 0, "", and [] are all falsy, so evaluation continues until the truthy "Python".
Question 60 of 60 · introduction to python as a programming language · Hard
Which statement best describes Python's execution model?
Not quite. Try another option.
Answer: Source code is compiled to bytecode, then run by an interpreter (virtual machine)
CPython first compiles source into platform-independent bytecode (.pyc), which is then executed by the Python Virtual Machine, combining compilation and interpretation.
That's unit 1
Answer a few questions and your score shows up here.
Nearly through. Did unit 1 of ECE181 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 1 of ECE181 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.