wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

If,elif,loop

Total questions: 24

Worksheet time: 14mins

Name
Class
Date
1.

What is the output of the following loop:-

for l in 'Jhon':

if l == 'o':

pass

print(l, end=", ")

a)

J, h, n,

b)

J, h, o, n,

c)

Error

d)

None of the given Options

2.

What is the output of the following range() function?


for num in range(2,-5,-1):

print(num, end=", ")

a)

2, 1, 0

b)

2, 1, 0, -1, -2, -3, -4, -5

c)

2, 1, 0, -1, -2, -3, -4

d)

0

3.

Given the nested if-else below, what will be the value x when the code is executed successfully.

a)

0

b)

4

c)

2

d)

3

4.

Given the nested if-else structure below, what will be the value of x after code execution completes.

a)

2

b)

0

c)

3

d)

4

5.

What is the output of the following nested loop?

a)

10 Chair

10 Table

20 Chair

20 Table

b)

10 Chair

10 Table

6.

What is the value of x?

a)

101

b)

None of the given options, this is an infinite loop

c)

99

d)

100

7.

What is the output of the following if statement?

a)

False

b)

True

8.

What is the output of the following for loop and range() function?

a)

-2, -1, -3, -4

b)

-2, -1, 0, 1, 2, 3

c)

-2, -1, 0

d)

-2, -3, -4

9.

What is the value of the var after the for loop completes its execution?

a)

20

b)

21

c)

10

d)

30

10.

What is the value of x after the following nested for loop completes its execution?

a)

99

b)

90

c)

100

d)

0

11.

What is the output of the following nested loop?

a)

10

11

12

13

b)

11

13

12.

What is the output of the following nested loop?

a)

10

11

12

13

b)

11

13

13.

Select which is true for: (for loop).

Hint: (We use while loop when we want to perform a task indefinitely until a particular condition is met.)

a)

Python’s for loop used to iterates over the items of list, tuple, dictionary, set, or string.

b)

We use for loop when we want to perform a task indefinitely until a particular condition is met

c)

else clause of for loop is executed when the loop terminates abruptly

d)

else clause of for loop is executed when the loop terminates naturally

14.

In programming, what is iteration?

a)

The repetition of steps within a program

b)

The order in which instructions are carried out

c)

A decision point in a program

d)

Testing a program to make sure it works

15.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
16.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

17.

The program above

a)

prints all the odd numbers between 1 and 20

b)

prints all even numbers between 1 and 20

c)

print all the odd numbers between 1 and 21

d)

prints all the even numbers between 1 and 21

18.

The above program prints

a)

Numbers 1 to 10 in reverse order

b)

Numbers 1 to 11 in reverse order

c)

Numbers 1 to 10

d)

Numbers 1 to 11

19.

How many times will 1 be printed

a)

3

b)

4

c)

5

d)

6

20.

Which of the following statements contains an error?

a)

Select * from emp where empid = 10003;

b)

Select empid from emp where empid = 10006;

c)

Select empid from emp;

d)

Select empid where empid = 1009 and lastname = ‘GELLER’;

21.

SELECT last_name, salary, (a)  

FROM employees;

22.

SELECT last_name "Name" , salary*12 "_____ _____"

FROM employees;

(a)  

23.

SELECT (a)   AS "Employees"

FROM employees;

24.

SELECT last_name ||' (a)   '||job_id

AS "Employee Details"

FROM employees;