0% found this document useful (0 votes)
3 views5 pages

Python Control Structures Quiz Questions

AAA

Uploaded by

esraayaksiz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Python Control Structures Quiz Questions

AAA

Uploaded by

esraayaksiz
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

çalışma sayfaları İsim

Python Control Structures


Sınıf
Toplam questions: 20
Çalışma sayfası süresi: 10dakika
Tarih
Eğitmen adı: Doodle with me

1. What are the three main programming structures?

a) Java, Python, Visual Basic b) Sequence, selection, iteration

c) Machine, assembly, high-level d) Structured, object-oriented, procedural

2.

What is the Output if the user enters:


Yes

a) Leave umbrella at home b) Take an umbrella

3. In a Python program , a control structure:

a) directs the order of execution of the statements in b) dictates what happens before te program starts and
the program after it terminates

c) defines program-specific data structures d) manages the input and output of control characters

[Link] 1/5
19.01.2025 20:41 Python Control Structures | Quizizz

4.

What is the output of the above program ?

a) Or here ? Or over here ? b) Am I here ? Or here ?

c) Am I here? d) Or here ?

5.

If the user inputs : 2<Enter> , what does the following code snippet print ?

a) May be b) Nothing printed

c) No d) Yes

e) Error

6. Function range(3) is equivalent to "

a) range(1,3,0) b) range(0,3,1)

c) range(1,3) d) range(0,3)

7. This operator means that one value is not equal to another value

a) >= b) !=

c) <= d) ==

8.

What is the output?

a) Program has a syntax error. b) True

c) 3 > 2 d) condition

[Link] 2/5
19.01.2025 20:41 Python Control Structures | Quizizz

9.

What is the output?

a) spam b) more than 23

c) 7 d) more than 7

10.

What is the output?

a) 3 b) 3
5
7

c) 7 d) 3
7

11.

What is the output?

a) NIL b) True
NIL

c) True d) True
NIL
NIL

[Link] 3/5
19.01.2025 20:41 Python Control Structures | Quizizz

12.

What is the output?

a) level 3 b) level 3
level 2
level 1
NIL

c) level 3 d) level 3
level 1 level 1
NIL

13. An If statement can be executed multiple times

a) FALSE b) TRUE

14. The ‘else’ statement is optional in Python

a) FALSE b) TRUE

15. It is possible to execute both the statements under if and else at the same time.

a) TRUE b) FALSE

16. There can be an else statement without an if statement

a) TRUE b) FALSE

17. The program generates an error message if the "else" statement is not defined

a) TRUE b) FALSE

18. Python supports ................ types of loops

Cevap.

[Link] 4/5
19.01.2025 20:41 Python Control Structures | Quizizz

19.

What is the output?

a) Hello world! b) Hello world


Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)

c) Hello world! d) Error

20.

What is the output if the user types "Python"?

a) Try again! b) Welcome

c) Error d) Enter your password

[Link] 5/5

Common questions

Powered by AI

Python supports multiple loop types, 'for' and 'while', which provide flexibility in addressing different control flow needs. 'For' loops are ideal for iterating over sequences and performing a fixed number of iterations, while 'while' loops work well when the number of iterations is not predetermined. This versatility allows programmers to choose loops that best fit the logic and efficiency requirements of their programs .

The function range(3) in Python generates a sequence of numbers starting from 0 up to, but not including, 3. The equivalent form is range(0,3,1), which specifies the starting point, stopping point, and step size .

A program might generate an error if an 'else' statement is needed for handling exceptions or providing default actions for unanticipated input values. This is particularly critical in programs that rely on exhaustive handling of all possible conditions, such as input validation systems or when constructing decision trees where every branch must be accounted for .

Not defining the 'else' statement in a program where alternative execution paths are necessary can lead to incomplete logic, where certain inputs might not result in any action or output. This can lead to bugs or unexpected behavior, particularly if there is no default action for unhandled conditions .

Python control structures, such as 'if', 'else', 'for', and 'while', influence the execution order by directing which paths the program follows based on conditions or iterations. For example, conditional blocks dictate execution based on true or false evaluations, while loops manage repeated execution of code blocks, thus controlling the flow and sequence of program operation .

Both 'if' and 'else' statements under the same condition cannot execute simultaneously in Python. This is because they represent mutually exclusive conditions; the 'if' block executes when the condition is true, and the 'else' block executes when the condition is false. Having them execute at the same time would contradict the logic of conditional branching .

The three main programming structures are sequence, selection, and iteration. Sequence determines the order in which statements are executed. Selection involves conditional statements that allow a program to take different paths based on certain conditions, such as 'if-else' statements. Iteration allows for the repetition of a block of code multiple times until a certain condition is met, using structures like 'for' and 'while' loops .

The 'else' statement is considered optional in Python because it is only executed when the 'if' condition is false. Omitting the 'else' statement means that if the 'if' condition is false, the program will simply skip to the next set of instructions after the 'if' block without executing any alternative code .

A logical error can occur in loops if an 'if' statement is used improperly, such as by not correctly setting conditions for the loop's continuation or termination. This can lead to infinite loops if the loop does not stop when expected or skips necessary iterations, resulting in incorrect behavior or program crashes .

The operator '!=' in Python is used to compare two values to check if they are not equal. It is commonly used in conditional statements where a program needs to execute a certain block of code only when two compared values differ, such as in loops that check for continuation conditions .

You might also like