Search Header Logo
Control Flow Revision

Control Flow Revision

Assessment

Presentation

Practice Problem

Hard

Created by

Joseph Dewhurst

FREE Resource

26 Slides • 37 Questions

1

PYTHON BLITZ

Control flow structures

media

2

While loop

  • Until a condition in the while statement's header is True, the body of the loop will be executed.

  • The body of the loop is demarcated by indentation (4 white spaces).

  • Iteration is a single execution of the body of the loop.

  • How often does the condition in the header of the while loop gets checked?

  • The condition in the while loop header gets checked at the beginning of a new iteration only after all the operations in the body of a loop have been executed.

3

Header condition of the while loop

  • any expression which evaluates to True

  • x > 0

  • a != b and a != c

  • True

  • a == b

  • score < = 500

  • Can you think of a condition?

4

Else, break and continue

or how to terminate or jump out of the while loop

media

5

Else, break and continue

  • Optional else statement after the body of the loop gets executed if the header condition in the while loops evaluates to False

  • Break statement executed in the body of the while loop terminates the loop without executing the else clause

  • Continue statement executed in the body of the while loop skips the rest of the operations in the body of the while loop and goes back to testing the expression.

6

Multiple Choice

It not known initially how many times the while loop will be iterated.

1

True

2

False

7

Multiple Select

If number zero is entered, the following will happen:

1

"If" statement will be exited, and while loop will executed again.

2

"If" statement will be exited, and while loop will be exited and the last "else" skipped.

8

Multiple Choice

The number of .. through the while loop is equal to the number of ..

1

iterations .. guesses

2

iterations .. incorrect guesses

3

iterations .. correct guessed

9

Open Ended

If the number 21 is entered, the following will happen:

10

Multiple Choice

Sign "!=" means

1

logical "OR"

2

logical "AND"

3

logical "EQUAL"

4

logical "NOT EQUAL"

11

Multiple Choice

In a Python program , a control structure:

1

directs the order of execution of the statements in the program

2

dictates what happens before te program starts and after it terminates

3

defines program-specific data structures

4

manages the input and output of control characters

12

Multiple Choice

An empty/null statement in python is ____________

1

go

2

pass

3

over

4

;

13

Multiple Choice

The order of statement execution in the form of top to bottom , is known as ______ construct

1

selection

2

repetition

3

sequence

4

flow

14

Multiple Choice

The ___________ construct allows to choose statements to be executed , depending upon the result of a condition.

1

selection

2

repetition

3

sequence

4

flow

15

Multiple Select

Which of the following statements will make a selection construct ?

1

if

2

for

3

if-else

4

while

16

Multiple Choice

Question image

What is the output of the above program ?

1

Am I here?

2

Or here ?

3

Am I here ? Or here ?

4

Or here ? Or over here ?

17

Multiple Choice

Question image

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

1

Yes

2

No

3

May be

4

Nothing printed

5

Error

18

Multiple Select

Function range(3) is equivalent to "

1

range(1,3)

2

range(0,3)

3

range(0,3,1)

4

range(1,3,0)

19

Multiple Select

In for a in _________ : , the blank can be filled with

1

an iterable sequence

2

a range() function

3

a single value

4

an expression

20

Multiple Choice

Consider the following loop given below :


for i in range(5):

print(i)


How many times will this loop run ?

1

5

2

0

3

infinite

4

Error

21

Multiple Choice

Question image

The program snippet above is syntactically correct

1

False

2

True

22

Multiple Choice

Question image

You should be at least 18 years to vote. What should be the expression in the if statement that will print


can vote.

1

age >= 18

2

age = 18

3

age == 18

23

Multiple Choice

Question image

What is the output of the program above.

1

can vote

2

can drink

3

can vote can drink

24

Multiple Choice

Question image

What is the output of the above program

1

can vote

can drink

2

can vote

3

can drink

4

none of the above

25

Multiple Choice

Question image

What is the output of the code above

1

go watch cartoons

2

can vote

3

go get a girlfriend/boyfriend

26

Multiple Choice

Question image

For which value of age, will the output "go drink" get printed

1

It will never print

2

17

3

22

27

Multiple Choice

Question image

The program above will print

1

Nothing

2

tends to drink

3

tends to chitchat

28

Multiple Choice

Question image

The code above will print

1

python

2

java

3

None

29

Python flow control

media

30

media

31

media

32

media

33

Multiple Choice

What is the output of print(10 - 4 * 2)

1

2

2

12

3

10

4

0

34

Multiple Choice

Which of these following is not an operator group?

1

Logical

2

Comparison

3

Bitwise

4

Membership

5

Output

35

Multiple Choice

What is the output of the following code


x = 6

y = 2

print(x ** y)

print(x // y)

1

66

0

2

36

0

3

66

3

4

36

3

36

Multiple Choice

Which python operator means 'less than or equal to'?

1

>=

2

>

3

<

4

<=

37

Multiple Choice

x = 5


print(x > 3 and x < 10)

1

True

2

False

38

Multiple Choice

x = 5

y = 3


print(x == y)

1

True

2

False

39

Multiple Choice

x = 5


x%=3


print(x)

1

2

2

2.0

3

3

4

3.0

40

media

41

media

42

media

43

media

44

media

45

media

46

media

47

media

48

Fill in the Blanks

Type answer...

49

Fill in the Blanks

Type answer...

50

Fill in the Blanks

Type answer...

51

Fill in the Blanks

Type answer...

52

Fill in the Blanks

Type answer...

53

Mastering Control Flow Statements

Learn how to effectively use control flow statements in Python to control the flow of your program and make it more efficient. Explore concepts like if-else statements, loops, and conditional expressions to gain mastery over control flow in Python.

54

Programming control structures are constructs in computer programming that enable developers to control the flow of a program's execution. These structures determine the order in which statements or blocks of code are executed. They are essential for making decisions, repeating tasks, and creating logical sequences within a program. There are three primary types of control structures in programming: Sequential, Selection, and Repetetion.

​Control Structures

55

Sequential Structure: In a sequential structure, code is executed one statement after another in a linear fashion. This is the default behavior of most programming languages. For example, if you have a series of statements, they will be executed in the order they appear in the code.

​Control Structures: Sequential

media

56

Selection (Conditional) Structure: Selection structures allow the program to make decisions based on certain conditions. These conditions are typically expressed using conditional statements such as if, else if (or elif), and else. The program executes different code blocks based on whether specific conditions are met.

​Control Structures: Selection

media

57

Repetition (Looping) Structure: Repetition structures enable the program to repeat a specific block of code multiple times. There are mainly two types of loops: for loops and while loops. They are used to iterate over collections, perform tasks a fixed number of times, or execute code until a specific condition is met.

​Control Structures: Repetition

media

58

Control Flow Statements

  • Conditional Statements: if, else if, else
  • Loop Statements: for, while
  • Jump Statements: break, continue

59

Multiple Choice

Which control flow statements are used in Python?

1

if, else if, else

2

for, while

3

break, continue

4

if, else if, else, for, while, break, continue

60

Python Control Flow Statements

Trivia: Python offers a variety of control flow statements to control the execution of code. These include if, else if, else, for, while, break, and continue. These statements allow programmers to make decisions, loop through code, and control the flow of their programs.

61

Mastering Control Flow Statements in Python

  • for item in iterable: Loop through each item in an iterable object.

  • While Loop: Repeat a block of code as long as a condition remains true.

  • Loop Control Statements: Use 'break' to exit a loop prematurely, 'continue' to skip the current iteration, and 'else' to execute code when the loop completes without a 'break'.

62

Multiple Choice

Which control flow statement is used to repeat a block of code as long as a condition remains true?

1

for loop

2

while loop

3

loop control statements

4

enumerate

63

While Loop

Trivia: The while loop is used to repeat a block of code as long as a condition remains true. It is a fundamental control flow statement in programming. The condition is checked before each iteration, and if it evaluates to true, the code block is executed. If the condition becomes false, the loop is terminated. The while loop is commonly used for tasks such as iterating over arrays or performing repetitive calculations. It provides flexibility and allows for dynamic control of the loop.

PYTHON BLITZ

Control flow structures

media

Show answer

Auto Play

Slide 1 / 63

SLIDE