In the program if mark >= 40: print('You have passed'), what happens when the user enters mark = 30?
- aThe pass message prints
- bThe body of
ifis skipped and the next statement is processed - cThe program crashes
- dThe mark is changed to 40
150 questions · 19 sections
In the program if mark >= 40: print('You have passed'), what happens when the user enters mark = 30?
if is skipped and the next statement is processedIn Python, the colon (:) placed at the end of an if condition serves to:
if blockThe minimum passing score used in the textbook example is:
To convert the keyboard input into an integer in int(input('Please enter your mark: ')), the function used is:
str()int()float()eval()If the condition of a single if is false:
In Python, the else keyword is used to:
if keywordif condition is not metif bodyThe combined construct used to choose between two alternative blocks is called the:
In an if...else construct, when the condition is true, the executed block is the:
elseifif...elseIn an if...else construct, when the condition is false, the executed block is the:
ifelseThe condition used inside an if...else typically consists of:
After the body of if or the body of else finishes, control passes to:
if...elseInside the body of if or else, what kind of statements may be used?
Two statements are correct about the if...else construct:
if conditionelseThe if...else flowchart in the textbook shows that after the diamond decision shape, control branches into:
In Bangladesh, the minimum age for voting eligibility used in the program is:
In the voter program if age >= 18:, a person aged exactly 18 will see:
The relational operator used to test voting eligibility is:
==>=<=!=The data type used to store the citizen's age in the voter program is:
strintfloatboolIf the citizen's age input is 15, the printed line is:
To check whether a number is even or odd, the operator used is the:
///%**A number is odd when:
num % 2 == 0num % 2 != 0num / 2 == 0num // 2 != 0In the textbook even/odd program, the input is converted using:
float(input(...))int(input(...))str(input(...))bool(input(...))For input num = 67, the program prints:
For input num = 100, the program prints:
A year is a leap year when it is divisible by:
In the leap-year program, the divisor that is checked first is:
According to the leap-year rule used in the program, the year 2012 is:
According to the rule, the year 1990 is:
The Python logical operators used in the leap-year condition are:
and and or&& and ||not and xoris and inAccording to the rule, the year 2000 is:
According to the rule, the year 1900 is:
In the leap-year program, the input is taken as a:
In the metres/feet conversion program, the conversion factor used is:
To convert feet to metres, the program computes:
num * 3.28num / 3.28num + 3.28num - 3.28To convert metres to feet, the program computes:
num / 3.28num * 3.28num + 3.28num ** 3.28In the conversion program, the result is rounded to:
To round the result, the built-in function used is:
int()round()floor()ceil()For Choice = 1 with input 25 feet, the printed metres value is approximately:
For Choice = 2 with input 60 metres, the printed feet value is approximately:
The data type used for the dimension input (feet or metres) in the conversion program is:
intfloatstrboolThe variable that holds the user's selection between Feet→Metres and Metres→Feet is named:
optionmodechoiceselectThe keyword elif is short for:
The elif statement is placed:
if statementif and else statementselse statementifThe main purpose of elif is to:
elif is described as a popular alternative to:
for loopif statementsmatch statementwhile loopIn an if / elif / else chain, how many else blocks may appear?
elifIn an if / elif / elif / else chain, the else block runs when:
elif is trueif is trueIn the positive / negative / zero program, the order of the checks is:
< 0 then > 0 else zero> 0 then < 0 else zero== 0 then < 0 else positive> 0 then == 0 else negativeFor num = 7, the program prints:
For num = -3, the program prints:
For num = 0, the program prints:
The default branch ("It is zero") is reached only when:
num > 0num < 0num > 0 and num < 0 are false (i.e. num == 0)The match statement is used as an alternative to using:
for loopselif statementsimport statementdef keywordWith the match statement, additional keywords that may be used are:
case and breakthen and doloop and nexttry and exceptIn an elif chain, the appropriate statement is selected based on:
In a match statement, the appropriate statement is usually selected based on:
The expression used with the match statement is called the:
After the keyword case and before the value, there should be at least:
A case line ends with:
The default branch in a match block is written as:
case _case defaultcase elsecase anyThe default case runs when:
In the match-based vowel/consonant program, the cases listed correspond to:
With input a, the match-based vowel/consonant program prints:
With input d, the match-based vowel/consonant program prints:
The first version (using match) accepts only:
In the alternative method (without match), the data structure used to hold all vowel characters is a:
The membership test used in the alternative method is:
inis==hasThe alternative method is designed to handle:
In if char in vowels:, what type does vowels need to support?
The program to find the largest of three integers uses:
for loopmatchif / elif / else chainwhile loopThe condition for declaring num1 as the largest is:
num1 > num2 or num1 > num3(num1 >= num2) and (num1 >= num3)num1 == num2 and num1 == num3num1 != num2 and num1 != num3The condition for declaring num2 as the largest is:
(num2 >= num1) and (num2 >= num3)(num2 > num3) or (num2 > num1)num2 == num1num2 < num1 and num2 < num3When all three numbers are 5, the program prints:
num1 is the largest numbernum2 is the largest numbernum3 is the largest numberFor inputs 10, 20, 30, the printed largest number is:
The logical operator used to combine the two relational tests inside each branch of the largest-number program is:
orandnotxorThe data type expected for num1, num2, num3 (matching the textbook code) is:
strintfloatboolIn daily life as well as in programming, repeating the same task is the motivation for using:
Loop control statements are used to execute a statement:
mainThree loop-related Python statements mentioned in the chapter are:
forwhilecontinue, break, passThe for loop is described as suitable when:
In a for loop, the variable used to count the iterations is called a:
In the format for CounterInitialization in Condition:, the keyword that links the counter and the condition is:
toinfromwithThe "Counter Initialization" section of a for loop sets:
The "Condition" section of a for loop specifies:
In Python, the function commonly used to generate the iteration values for a for loop is:
rangelenprintinputWith range(1, 6), the loop variable takes the values:
With range(1, 6, 1), the step value used in iteration is:
With range(1, 6, -1), the loop body in Python:
Loop body statements continue to execute until:
To print the text "ICT" exactly five times using a for loop, the textbook uses:
for i in range(5, 1):for i in range(1, 6):for i in range(0, 6):for i in range(1, 5):The number of times the body of for i in range(1, 6): executes is:
The variable i used in the loop is also called the:
After the loop in Practical Problem #10 finishes, the printed output contains the word ICT exactly:
In the program that prints a word 50 times, the upper bound used in range(1, ...) is:
To take the word as input, the function used is:
int(input(...))input(...)float(input(...))read(...)If the user enters "Computer", the loop prints "Computer" how many times in total?
The variable that holds the input word is named:
wordvartextsThe condition used inside the loop to detect odd numbers is:
i % 2 == 0i % 2 != 0i // 2 == 0i % 3 == 0In for i in range(1, 101):, the values of i range over:
The total count of odd numbers printed by the program is:
The first odd number printed by the program is:
The last odd number printed by the program is:
The program demonstrates a loop that contains:
for loop onlyfor loop with an inner if conditionfor loopswhile loopThe number-triangle program prints a pattern that on row i shows the digits:
iii, i-1, …, 1The structure used to create the triangle pattern is a:
for loopfor loop (a loop inside another loop)match statementwhile-else blockTo keep the printed digits on the same line in Python, the print call uses the parameter:
sependflushfileIn the textbook output, the last row of the triangle contains:
The number of rows in the printed triangle (per the textbook output) is:
The empty print() call at the end of the inner loop is used to:
To print the multiplication table of a number from 1 to 10, the loop used is:
for i in range(0, 10):for i in range(1, 11):for i in range(1, 10):for i in range(0, 11):Inside the multiplication-table loop, the product is computed as:
prod = num + iprod = num * iprod = num / iprod = num - iFor input num = 3, the value printed for i = 7 is:
The total number of lines printed for one number's multiplication table is:
For input num = 3, the largest product printed by the program is:
To take the number as input in the multiplication-table program, the conversion function used is:
str()int()float()bool()Which of the following is a relational operator in Python?
=>=+**Which operator returns the remainder of an integer division in Python?
///%**Which is a Python logical operator?
&&||and!Which condition correctly checks if n is divisible by 4?
n / 4 == 0n % 4 == 0n // 4 != 0n + 4 == 0The expression (year % 400 == 0 or (year % 100 != 0 and year % 4 == 0)) evaluates to True when:
In the if statement of Python, the body is identified by:
{ ... }doThe maximum number of elif branches in a single chain is:
Which of the following best describes a flowchart of if...else?
Two correct statements about match in Python:
case lines may appearcase ends with a colondefaultCompared to a long if / elif / else chain that compares one variable, a match statement is mainly used to:
for loopsThe statement for i in range(1, 6): will iterate exactly:
Inside the loop body, the counter variable changes:
range, until the condition failsThe chapter lists which loop-related keywords besides for and while?
continue, break, passdo, until, repeatgoto, next, lasttry, except, finallyIn the program for i in range(1, 101): if (i % 2 != 0): print(i), removing the inner if would print:
The vowel-list-based check if char in vowels: is more general than the match-based version because it:
printIn the largest-of-three program, when two of the three numbers are equal and both larger than the third, the printed number is:
In the match-based vowel program, replacing the _ in case _: would:
In the metres/feet conversion, the use of else (instead of an additional elif) means the program treats:
In Python, indentation level inside a block must be:
Which is true about the body of else in if...else?
if condition is trueif condition is falseIn the format of for CounterInitialization in Condition:, the colon at the end of the header line marks the:
In the multiplication-table program, the inner expression print(num, '*', i, '=', prod) produces output where the items are separated by:
print default sep)Two correct statements about the elif statement:
ifIn Practical Problem #2 (mark ≥ 40), the textbook prints "You have passed" when the input is:
Which of the following loops is most appropriate when the number of iterations is known in advance?
whileformatchifWith range(1, 51) in the print-50-times program, the value of i reaches up to (but not including):
In the leap-year condition, which Python operator is used to check inequality with 0?
=!!=<>==!For input age = 25 in the voter program, the output is:
Two correct statements about the match statement:
_The chapter describes the else body as the alternative to the if body when:
Which is a correct way to build a vowel-set in Python (matching the chapter's spirit)?
vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']vowels = (a + e + i + o + u)vowels = aeiouvowels = "vowels"The output of for i in range(1, 6): print('ICT') is:
ICT printed 5 times on separate linesICT printed onceIn the chapter's number-triangle program, the inner loop variable j runs from:
i + 1i + 1i down to 1In the chapter's even/odd program, what does the program print for num = 0?
0 % 2 == 0)Two correct statements about for and range:
range(1, n) iterates over 1, 2, …, n-1range is the step sizerange function reads input from the keyboard