What is the output of this Python code? print(9 // 2)
A5.
B4.5.
C4. ✓ Correct answer
D3.
✓ Correct answer: 4.
Full explanation
4. In Python, // is floor division, so 9 // 2 is 4. Why the others are wrong: 5. — 5 would be the result of rounding 4.5 up, but floor division gives 4. 4.5. — 4.5 is the result of 9 / 2, not of 9 // 2. 3. — 3 is not the result of 9 // 2.
In Python, which function tells you the type of a value?
Alen()
Btype() ✓ Correct answer
Cprint()
Dstr()
✓ Correct answer: type()
Full explanation
type(). The type() function returns the type of a value, such as int or str. Why the others are wrong: len() — len() returns the length of a value, not its type. print() — print() shows a value on the screen, not its type. str() — str() changes a value into text, not its type.
In Python, which keyword begins a loop that keeps running while a condition is true?
Adef
Bwhile ✓ Correct answer
Cif
Dreturn
✓ Correct answer: while
Full explanation
In Python, the keyword that begins a loop that keeps running while a condition is true is while. Why the others are wrong: def — def defines a function, it does not begin a loop. if — if makes a choice once, it does not repeat a block while a condition is true. return — return sends a value back from a function, it does not begin a loop.
What is the output of this Python code? print(15 % 4)
A3 ✓ Correct answer
B4
C1
D0
✓ Correct answer: 3
Full explanation
3. In Python, the % operator gives the remainder of a division, and 15 divided by 4 is 3 with a remainder of 3. Why the others are wrong: 4 — 4 is the number divided by, not the remainder. 1 — 1 is the remainder of 13 divided by 4, not of 15 divided by 4. 0 — 0 would be the remainder only if 15 were exactly divisible by 4, but it is not.
What is the output of this Python code? print(10 - 4 * 2)
A12
B10
C4
D2 ✓ Correct answer
✓ Correct answer: 2
Full explanation
The correct answer is 2. Multiplication is done first, so 4 * 2 is 8, and 10 - 8 is 2. Why the others are wrong: 12 — 12 would be the result if the subtraction were done first, but multiplication comes first. 10 — 10 is not the result of 10 - 4 * 2. 4 — 4 is not the result of 10 - 4 * 2.
ProgrammingPython ProgrammingBPSCID: BPP-2785
In Python, a comment begins with the symbol:
A/*
B//
C# ✓ Correct answer
D--
✓ Correct answer: #
Full explanation
In Python, a comment begins with the # symbol.
ProgrammingPython ProgrammingFPSCID: FPP-11397
In programming, a variable is used to:
APrint output
BDraw graphics
CStore data ✓ Correct answer
DConnect to the internet
✓ Correct answer: Store data
Full explanation
In programming, a variable is used to store data. The correct answer is Store data.
ProgrammingPython ProgrammingFPSCID: FPP-11398
In Python, which data type is used for whole numbers?
Astr
Bfloat
Cint ✓ Correct answer
Dbool
✓ Correct answer: int
Full explanation
In Python, the int data type is used for whole numbers.
ProgrammingPython ProgrammingFPSCID: FPP-11399
In Python, which data type is used for text?
Aint
Bfloat
Cstr ✓ Correct answer
Dlist
✓ Correct answer: str
Full explanation
In Python, the str data type is used for text.
ProgrammingPython ProgrammingFPSCID: FPP-11400
In Python, the output of print(2 + 3) is:
A2
B23
C5 ✓ Correct answer
D6
✓ Correct answer: 5
Full explanation
In Python, the output of print(2 + 3) is 5.
ProgrammingPython ProgrammingPPSCID: LTP-7690
In Python, which keyword starts a loop that repeats while a condition remains true?
Afor
Bif
Cwhile ✓ Correct answer
Ddef
✓ Correct answer: while
Full explanation
In Python the while keyword starts a loop that repeats while a condition remains true, checking the condition before each round.
ProgrammingPython ProgrammingPPSCID: LTP-7691
In Python, which function is used to display output on the screen?
Ascan()
Bshow()
Cdisplay()
Dprint() ✓ Correct answer
✓ Correct answer: print()
Full explanation
The print() function is used in Python to display output on the screen.
ProgrammingPython ProgrammingPPSCID: LTP-7692
Which Python data type is mutable, meaning its contents can be changed after creation?
AList ✓ Correct answer
BTuple
CString
DInteger
✓ Correct answer: List
Full explanation
A list is mutable in Python, so items can be added, removed or changed after the list is created.
ProgrammingPython ProgrammingPPSCID: LTP-7693
Which Python data type is immutable, meaning it cannot be changed after creation?
AList
BTuple ✓ Correct answer
CDictionary
DSet
✓ Correct answer: Tuple
Full explanation
A tuple is immutable in Python, so its items cannot be changed after the tuple is created.
ProgrammingPython ProgrammingPPSCID: LTP-7694
In Python, what does the expression 2 ** 3 evaluate to?
A6
B9
C8 ✓ Correct answer
D5
✓ Correct answer: 8
Full explanation
In Python the expression 2 ** 3 evaluates to 8, because ** is the power operator and 2 raised to 3 is 8.
ProgrammingPython ProgrammingPPSCID: LTP-7695
In Python, blocks of code such as the body of a loop are defined by:
ACurly braces
BSemicolons
CRound brackets
DIndentation ✓ Correct answer
✓ Correct answer: Indentation
Full explanation
In Python, blocks of code are defined by indentation, with the same indent marking the statements that belong together.
ProgrammingPython ProgrammingPPSCID: LTP-7696
In Python, which function returns the number of items in a list?
Alen() ✓ Correct answer
Bcount()
Csize()
Dlength()
✓ Correct answer: len()
Full explanation
The len() function returns the number of items in a list or other sequence in Python.
ProgrammingPython ProgrammingPPSCID: LTP-7697
A Python dictionary stores data as:
AOnly numbers
BKey-value pairs ✓ Correct answer
COnly images
DSorted pages
✓ Correct answer: Key-value pairs
Full explanation
A Python dictionary stores data as key-value pairs, so each value is reached through its key.
ProgrammingPython ProgrammingPPSCID: LTP-7698
In Python, which symbol starts a single-line comment?
A//
B/*
C# ✓ Correct answer
D--
✓ Correct answer: #
Full explanation
In Python the # symbol starts a single-line comment, and everything after it on that line is ignored.
ProgrammingPython ProgrammingPPSCID: LTP-7699
Python is best described as which type of language?
AMachine code only
BAssembly only
CA markup language
DInterpreted ✓ Correct answer
✓ Correct answer: Interpreted
Full explanation
Python is an interpreted language, so its code is executed line by line by the Python interpreter.