wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Quiz-5 AX

Total questions: 148

Worksheet time: 3hrs 55mins

Name
Class
Date
1.
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
2.
Why is iteration important?
a)
It determines the order in which instructions are carried out
b)
It allows code to be simplified by removing duplicated steps
c)
It allows multiple paths through a program
d)
It ensures the code works correctly
3.
Which two statements are used to implement iteration?
a)
IF and WHILE
b)
ELSE and WHILE
c)
FOR and WHILE
d)
IF and ELSE
4.
Which type of loop iterates until instructed otherwise?
a)
FOR loop
b)
A count-controlled loop
c)
Repeat-once loop
d)
WHILE loop
5.
The condition for a while loop to continue could include which of the following?
a)
While something equals something
b)
While something is greater than something
c)
While something is True
d)
All of these
6.
Which of the following symbols is used in Python to mean "Equal to"?
a)
=
b)
!=
c)
==
d)
>=
7.
Which of the following symbols is used in Python to mean "Not equal to"?
a)
==
b)
!=
c)
<>
d)
><
8.
Which of the following symbols is used in Python to mean "Greater than or equal to"?
a)
<=
b)
>>
c)
>=
d)
=>
9.
a)
5
4
3
2
1
b)
4
3
2
1
0
c)
5  4  3  2  1
d)
4  3  2  1  0
10.
a)
5
4
3
2
1
b)
4
3
2
1
0
c)
5  4  3  2  1
d)
4  3  2  1  0
11.
a)
5
4
3
2
1
b)
5  4  3  2  1
c)
4
3
2
1
0
d)
4  3  2  1  0
12.
a)
10  8  6  4  2
b)
10
8
6
4
2
c)
2  4  6  8  10
d)
10  9  8  7  6  5  4  3  2  1
13.
a)
12  9  6  3  0
b)
0  3  6  9  12
c)
9  6  3  0
d)
0  3  6  9
14.
a)
0  5  10
b)
5  10
c)
0  5  10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90  95  100  105  110  115  120  125  130  135  140......etc
d)
12  7  2
15.
a)
12  17   22
b)
5
c)
12
d)
5  10
16.
a)
Hello world!
b)
Hello world
c)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
......(repeated continuously)
d)
Error
17.
a)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
b)
Hello world!
c)
Hello world!
break              
d)
Error
18.
Which of the following symbols is used in Python to mean "Less than or equal to"?
a)
<<
b)
=<
c)
<=
d)
!=
19.
a)
Hello world!
b)
Error
c)
Hello world!
False
d)
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
(repeated continuously)
20.
a)
Welcome
b)
Try again!
c)
Error
d)
Enter your password
21.

For the code shown, what will happen?

a)

It will print all the numbers from 0 to 11

b)

It will print all the numbers from 0 to 11 in increments of 3

c)

Infinite loop

d)

It will not run (Syntax error)

22.

A while loop is used when

a)

You know how many times you are going to loop

b)

You want to loop for an unknown number of times, and possibly forever

c)

You only want to run the code in the loop once

d)

You see the word while in the problem description

23.

What is the final value of n?

(a)  

24.

Why is iteration important?

a)

It determines the order in which instructions are carried out

b)

It allows code to be simplified by removing duplicated steps into a block that can be executed many times

c)

It allows multiple paths through a program

d)

It ensures the code works correctly

25.

What is the output of this code?

a)

It would print 'So good to see you' infinite number of times

b)

There would be no output

c)

It would print an error message.

d)

It would print 'Enter correct code'.

26.

The condition for a while loop to continue could include which of the following?

a)

While something equals something

b)

While something is True

c)

While something is greater than something

d)

All of these

27.

What is the final value of the variable 'number'?

(a)  

28.

What is the output?

a)

5

4

3

2

1

b)

5 4 3 2 1

c)

4

3

2

1

0

d)

4 3 2 1 0

29.

To increment means to

a)

increase the value of a variable

b)

decrease the value of a variable

c)

add 1 to the variable

d)

subtract 1 from the variable

30.

What is the output?

a)

12 9 6 3 0

b)

0 3 6 9 12

c)

0 3 6 9

d)

9 6 3 0

31.

A counter is (check ALL that apply)

a)

A variable used in a loop to count the number of times something happened

b)

usually initialised to zero

c)

usually incremented inside the loop

d)

a person with a pen and paper

e)

used only outside of the loop

32.

What is the output?

a)

0 5 10

b)

5 10

c)

0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 105 110 115 120 125 130 135 140......etc

d)

12 7 2

33.

What is the output?

a)

12 17 22

b)

12

c)

5

d)

5 10

34.

What is the output?

a)

Hello world

b)

Hello there

c)

Error

d)

Hello there

Hello there

Hello there

Hello there

Hello there

...(forever)

35.

What is the output?

a)

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

(repeated continuously)

b)

Hello world!

c)

Hello world!

break

d)

Error

36.

What is the output?

a)

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

Hello world!

(repeated continuously)

b)

Hello world!

c)

Hello world!

break

d)

Error

37.

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

a)

Welcome

b)

Try again!

c)

Error

d)

Enter your password

38.

What will this code output?

a)

Nothing

b)

1

4

7

Bye

c)

Jon

Jon

Bye

d)

Jon

Jon

Jon

Bye

e)

Jon

Jon

Jon

Jon

Jon

Jon

Bye

39.

What will be the output of this code?

a)

This loop will not run

b)

An infinite loop

c)

It'll print all numbers from 1-9

d)

It'll print all numbers from 1-10

40.

What will happen if the user enters the sequence (each time through the loop)

2, 5, 3, q

a)

Loop finishes and prints 10

b)

Loop never ends

c)

Program throws a ValueError when calling the int() function

d)

Program asks user to enter another num

41.
a)

Welcome

b)

Error

c)

Try again!

d)

Enter your password

42.
a)

Hello world!

b)

Hello world!

False

c)

Error

d)

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

43.
a)

0 1 2

b)

012

c)

0

1

2

d)

0 1 2 3

e)

0

1

2

3

44.
a)

l e t t e r s

b)

letters

c)

0 1 2 3 4 5 6

d)

l e t t e r

e)

letter

45.
a)

vortex vortex vortex vortex

b)

vortex

vortex

vortex

vortex

c)

vortex, vortex, vortex, vortex

d)

0 1 2 3

e)

0 1 2 3 4

46.
a)

6

b)

0

1

3

6

c)

0

1

2

3

d)

5

e)

3

47.
a)

2

b)

16

c)

32

d)

2

4

8

16

e)

2

4

8

16

32

48.
a)

cat

cat

cat

cat

cat

b)

catcatcatcatcat

c)

cat cat cat cat cat

d)

5

4

3

2

1

e)

0

49.
a)

count

b)

count artistic

c)

1

d)

8

e)

7

50.
a)

10

b)

2

c)

3

d)

8

e)

an error will be received

51.
a)

0 1 2 3 4

b)

0 1 2 3 4 5

c)

5

d)

4

e)

this won't work properly, infinite loop

52.
a)

0 2 4 6 8 10

b)

p n e e e n

c)

10

d)

n

e)

0

53.
a)

b = = k = = p = r

b)

= e e = e e = e =

c)

= = = =

d)

e e e e e

e)

b k p r

54.
a)

$ $ $ $ $

$ $ $ $

$ $ $

$ $

b)

$ $ $ $ $

c)

$ $

d)

$ $ $ $

e)

$ $ $ $ $

$ $

55.
a)

20

b)

25

c)

21

d)

infinite loop

56.
a)

sum: 39

b)

sum: 38

c)

sum: 24

d)

sum: 57

57.
a)

11

b)

7 8 9 10 11

c)

12

d)

7 8 9 10 11 12

58.
a)

25

b)

35

c)

26

d)

46

59.
a)

0

b)

3 5 7 9

c)

24

d)

error

60.

the output of this program group --------

a)

A

b)

B

61.

Print i as long as i is less than 6 and i is initiated with the value of 1 :


Which program is correct

a)
b)
62.

Print i where i is initiated with the value of 0 as long as i is less than 6 and continue to the next iteration if i is 3


To match this output which one is the correct program

a)
b)
63.

Stop the loop if i is 3.

a)

break

b)

continue

64.

In the loop, when i is 3, jump directly to the next iteration.

a)

break

b)

continue

65.

What does the flowchart in the image represent?

a)

The syntax of a while loop in Python

b)

The execution flow of a while loop in Python

c)

The error handling in a while loop in Python

d)

The variable declaration in a while loop in Python

66.

What will be the output of the given Python code snippet?

a)

The code will print "Hello World" once.

b)

The code will print "Hello World" ten times.

c)

The code will print "Hello World" indefinitely.

d)

The code will cause an error.

67.

What will happen when the following Python code is executed?

a)

The loop will run indefinitely because 's' is never typed.

b)

The loop will end immediately without waiting for user input.

c)

The loop will ask the user to input a letter and will only end when the user types 's'.

d)

The loop will cause an error because the variable 'letter' is not properly defined.

68.

What is the initial value of the variable 'letter' in the given Python code?

a)

's'

b)

' '

c)

''

d)

None

69.

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

70.

The equivalent of the above for loop using the while syntax would be

a)
b)
c)
d)
71.

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

72.

The program above prints

a)

Numbers between 1 and 100 that are multiples of 5

b)

Numbers between 1 and 100

c)

Numbers between 1 and 100 divisible by 5

d)

Numbers between 1 and 101 that are multiples of 5

73.

The code above prints all numbers between 1 and 30 that are

a)

not divisible by 5

b)

divisible by 5

74.

The program above prints the sum of

a)

all odd numbers less than 100

b)

all even numbers less than 100

c)

all numbers less than 100

75.

The program above prints the sum of all the numbers between 0 and 101 that are

a)

alternate odd numbers

b)

alternate even numbers

c)

alternate numbers

76.

The program above prints each number between 1 and 10

a)

as many times as the number itself

b)

10 times

c)

11 times

77.

How many times will 1 be printed

a)

3

b)

4

c)

5

d)

6

78.

for i in 100 :

print ( i )

a)

Syntax error

b)

prints numbers 0 to 100

c)

prints numbers 1 to 100

d)

prints numbers 0 to 99

e)

prints numbers 1 to 99

79.

What is the output of the program above

a)

10

b)

15

c)

18

d)

17

e)

16

80.

A while loop equivalent of the for loop above is

a)
b)
c)
d)
81.

What is the value of the variable sum after the code above executes

a)

54

b)

44

c)

64

d)

34

e)

74

82.

str()

a)

converts any type of value to string data type

b)

converts string to integer

83.

Fixed number of fibonacci series

a)

0 and 1

b)

1 and 2

c)

1 and 1

84.

Choose the correct fibonacci series

a)

0 1 2 3 5 8 13

b)

0 1 1 2 3 5 8

c)

1 2 3 5 8 15 23

85.

Examples of fibonacci

a)
b)
c)
86.

Correct sequence of while loop

a)

Condition, Action, initialisation, Increment/decrement

b)

initialisation, Condition, Action, Increment/decrement

c)

initialisation, Condition, Increment/decrement, Action

87.

What is the result of following Program in python3

a=4

b=2

c=a-b*6

print("\n a={0} \n b={1} \n c={2}".format(a,b,c))

a)

12

b)

-8

c)

8

d)

-12

88.

What is the result of following Program in python3

for i in range(3,0,-1)

print("{0} Python".format(i))

a)

3 Python

2 Python

1 Python

b)

2 Python

1 Python

0 Python

c)

3 Python

d)

error

89.

What is the result of following Program in python3

if(32%2==0):

print("32")

else:

print("2")

a)

2

b)

32

c)

error

90.

What is the result of following Program in python3

for i in range(1,4):

print(i)

if(i==2):

break;

a)

1

b)

1

2

c)

1

2

3

4

d)

error

91.
The Python code below is an example of which programming term?
person = input('Enter your name: ')
print('Hello', + person)
a)
concatenation
b)
algorithm
c)
conditional
d)
loop
92.
The Python code below is an example of which programming term?
x = int(input("Please enter an integer: "))
if x<0:
  x=0
  print("Your negative number was changed to zero")
a)
concatenation
b)
algorithm
c)
conditional
d)
loop
93.
For which programming language will inconsistent indentation cause a syntax error?
a)
HTML
b)
JavaScript
c)
Python
d)
C#
94.

If a=(1,2,3,4), a[1:-1] is _________

a)

a) Error, tuple slicing doesn’t exist

b)

b) [2,3]

c)

c) (2,3,4)

d)

d) (2,3)

95.

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1]?

a)

a) [2, 33, 222, 14]

b)

b) Error

c)

c) 25

d)

d) [25, 14, 222, 33, 2]

96.

What is the order of precedence in python?

a)

a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

b)

b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction

c)

c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition

d)

d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

97.

Which of the following functions is a built-in function in python?

a)

a) factorial()

b)

b) print()

c)

c) seed()

d)

d) sqrt()

98.

To add a new element to a list we use which Python command?

a)

a) list1.addEnd(5)

b)

b) list1.addLast(5)

c)

c) list1.append(5)

d)

d) list1.add(5)

99.

What will be the output of the following Python statement?

>>>"abcd"[2:]

a)

a) a

b)

b) ab

c)

c) cd

d)

d) dc

100.

What will be the output of the following Python statement?

>>>"abcd"[2:]

a)

a) a

b)

b) ab

c)

c) cd

d)

d) dc

101.

What will be the output of the following Python code?

>>> str1 = 'hello'

>>> str2 = ','

>>> str3 = 'world'

>>> str1[-1:]

a)

a) olleh

b)

b) hello

c)

c) h

d)

d) o

102.

Suppose list1 is [2445,133,12454,123], what is max(list1)?

a)

a) 2445

b)

b) 133

c)

c) 12454

d)

d) 123

103.

Which of the following statements create a dictionary?

a)

a) d = {}

b)

b) d = {“john”:40, “peter”:45}

c)

c) d = {40:”john”, 45:”peter”}

d)

d) All of the mentioned

104.

What will be the output of the following Python code?

a={1:"A",2:"B",3:"C"}

b={4:"D",5:"E"}

a.update(b)

print(a)

a)

a) {1: ‘A’, 2: ‘B’, 3: ‘C’}

b)

b) Method update() doesn’t exist for dictionaries

c)

c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}

d)

d) {4: ‘D’, 5: ‘E’}

105.

Find the output of the following:-

int sum=0, n=10;

for( int i=n; i>=1; -- i)

{ sum= sum+ i; }

System.out.println(" Sum is "+ sum) ;

a)

55

b)

10

c)

28

d)

50

106.

Consider these functions:

push() : push an element into the stack

pop() : pop the top-of-the-stack element

top() : returns the item stored in top-of-the-stack-node

What will be the output after performing these sequence of operations


push(20);

push(4);

top();

pop();

pop();

pop();

push(5);

top();

a)

20

b)

4

c)

5

d)

Stack Underflow

107.

How many times do while loop is guaranteed to execute?

a)

0

b)

1

c)

depends upon condition

d)

No gurantee

108.

Which of the following is an exit controlled loop?

a)

While loop.

b)

For loop.

c)

do-while loop.

d)

None of the above.

109.

print([i.lower() for i in "HELLO"])

a)

[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

b)

‘hello’

c)

[‘hello’]

d)

hello

110.

print([[i+j for i in "abc"] for j in "def"])

a)

[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]

b)

[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]

c)

[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]

d)

[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

111.

print([if i%2==0: i; else: i+1; for i in range(4)])

a)

[0, 2, 2, 4]

b)

[1, 1, 3, 3]

c)

error

d)

none of the mentioned

112.

Write the list comprehension to pick out only negative integers from a given list ‘a’.

a)

[x<0 in a]

b)

[x for x<0 in a]

c)

[x in a for x<0]

d)

[x for x in a if x<0]

113.

Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

a)

[x**3 for x in l]

b)

[x*3 for x in l]

c)

[x**3 in l]

d)

[x^3 in l]

114.

Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’]

w="hello"

v=('a', 'e', 'i', 'o', 'u')

a)

[x for w in v if x in v]

b)

[x for x in w if x in v]

c)

[x for x in v if w in v]

d)

[x for v in w for x in w]

115.

Write a list comprehension for producing a list of numbers between 1 and 1000 that are divisible by 3.

a)

[x in range(1, 1000) if x%3==0]

b)

[x for x in range(1000) if x%3==0]

c)

[x%3 for x in range(1, 1000)]

d)

[x%3=0 for x in range(1, 1000)]

116.

Write a list comprehension equivalent for the Python code shown below.

a)

[i for i in range(1, 100) if int(i*0.5)==(i*0.5)]

b)

[i for i in range(1, 101) if int(i*0.5)==(i*0.5)]

c)

[i for i in range(1, 101) if int(i*0.5)=(i*0.5)]

d)

[i for i in range(1, 100) if int(i*0.5)=(i*0.5)]

117.

Write a list comprehension to produce the list: [1, 2, 4, 8, 16, ..., 1024].

a)

[2**x for x in range(0, 10)]

b)

[2**x for x in range(11)]

c)

[2*x for x in range(0, 11)]

d)

[2*x for x in range(1, 11)]

118.

What will be the output of the following Python code?

a)

[‘good’, ‘oh’, ‘excellent’, ‘450’ ]

b)

[‘good’]

c)

[‘good’, ‘#450’]

d)

[‘oh!’, ‘excellent!’, ‘#450’]

119.

What is used to separate elements in a list?

a)

Bracket

b)

Comma

c)

Full Stop

d)

Space

120.

An empty list can be declared as

a)

fruitList = ""

b)

fruitList = ["empty"]

c)

fruitList == []

d)

fruitList = []

121.

Each item in a list has an "address" or index. The first index in a Python list is what?

a)

1

b)

0

c)

a

d)

A

122.

What will be the output?

names1 = ['Amir', 'Bala', 'Chales']

if 'amir' in names1:

print(1)

else:

print(2)

a)

None

b)

1

c)

2

d)

error

123.

What brackets are used to create a list?

a)

()

b)

[]

124.

fruitlist1 = ["banana","grapes","apple"]

fruitlist2 = ["banana","grapes","apple","grapes"]

fruitlist3 = fruitlist1 + fruitlist2

print(fruitlist3)

a)

["banana","grapes","apple"]

b)

["banana","grapes","apple","grapes"]

c)

fruitlist1 + fruitlist2

d)

["banana","grapes","apple","banana","grapes","apple","grapes"]

125.

mylist = ["a","b"]

print(mylist*2)

a)

["a","b","a","b"]

b)

["a","b","a"]

c)

["a","b","a","a"]

d)

["a","b","a"

126.

mylist = ["a","b"]

mylist[1] = "c"'

print(mylist)

a)

["a","c"]

b)

["a","b"]

c)

["a","b","c"]

d)

mylist

127.

Consider this list, what will be the highest index the list can have:

li=[1,2,3,4,5]

a)

2

b)

3

c)

4

d)

5

128.

Consider this list, what will be the output of the following:


li=[1,2,3,4,3,2,1]

print(li[-3])

a)

4

b)

3

c)

2

d)

1

129.

Consider this list, what will be the output of the following:


li=[1,2,3,4,3,2,1]

print(li[3])

a)

4

b)

3

c)

2

d)

1

130.

Consider this list, what will be the output of the following:


li=[1,2,3,4,3,2,1]

print(li[3:4])

a)

1

b)

2

c)

3

d)

4

131.

Write the output of the following code

L=[1, 2, 3, 4, 5, [6,7,8]]

print(L[5])

a)

[6, 7, 8]

b)

6, 7, 8

c)

6

d)

Error

132.

Q12. Write the output of the following code :

>>>L=[“Amit”,”Sumit”,”Naina”]

>>>print(L[1:-1])

a)

[‘Sumit’]

b)

[a]

c)

[Naina]

d)

None of the above

133.

L=[1,2,3,4,5]

for i in L:      

print(i, end=” “)    

a)

a. 1 2 3 4 5

b)

b. 1, 3, 5

c)

c. 1, 2, 3, 4, 5

d)

d. None of the above

134.

Write the output of the following code :

L=[“Amit”,”Sumit”,”Naina”]

L1=[“Sunil”]

print(L + L1)

a)

a. [‘Amit’ , ‘Sumit’ , ‘Naina’ , [‘Sunil’]]

b)

b. [‘Amit’ , ‘Sumit’ , ‘Naina’ , ‘Sunil’]

c)

c. List can not concatenate

d)

d. None of the above

135.

Result of list slice is also a list?(T/F)

a)

a. True

b)

b. False

136.

Index of last element in list is n-1, where n is total number of elements.(T/F)

a)

a. True

b)

b. False

137.

In list slicing, the start and stop can be given beyond limits. If it is then

a)

raise Index Error exception

b)

raise ValueError exception

c)

Return elements falling between specified start and stop values

d)

return the entire list

138.

Consider this list, what will be the output of the following:


li=[1,2,3]

print(li[3])

a)

1

b)

2

c)

3

d)

error

139.

print([i.lower() for i in "HELLO"])

a)

[‘h’, ‘e’, ‘l’, ‘l’, ‘o’]

b)

‘hello’

c)

[‘hello’]

d)

hello

140.

print([[i+j for i in "abc"] for j in "def"])

a)

[‘da’, ‘ea’, ‘fa’, ‘db’, ‘eb’, ‘fb’, ‘dc’, ‘ec’, ‘fc’]

b)

[[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]]

c)

[[‘da’, ‘db’, ‘dc’], [‘ea’, ‘eb’, ‘ec’], [‘fa’, ‘fb’, ‘fc’]]

d)

[‘ad’, ‘ae’, ‘af’, ‘bd’, ‘be’, ‘bf’, ‘cd’, ‘ce’, ‘cf’]

141.

print([if i%2==0: i; else: i+1; for i in range(4)])

a)

[0, 2, 2, 4]

b)

[1, 1, 3, 3]

c)

error

d)

none of the mentioned

142.

Write the list comprehension to pick out only negative integers from a given list ‘a’.

a)

[x<0 in a]

b)

[x for x<0 in a]

c)

[x in a for x<0]

d)

[x for x in a if x<0]

143.

Write a list comprehension for number and its cube for l=[1, 2, 3, 4, 5, 6, 7, 8, 9]

a)

[x**3 for x in l]

b)

[x*3 for x in l]

c)

[x**3 in l]

d)

[x^3 in l]

144.

Read the information given below carefully and write a list comprehension such that the output is: [‘e’, ‘o’]

w="hello"

v=('a', 'e', 'i', 'o', 'u')

a)

[x for w in v if x in v]

b)

[x for x in w if x in v]

c)

[x for x in v if w in v]

d)

[x for v in w for x in w]

145.

Write a list comprehension for producing a list of numbers between 1 and 1000 that are divisible by 3.

a)

[x in range(1, 1000) if x%3==0]

b)

[x for x in range(1000) if x%3==0]

c)

[x%3 for x in range(1, 1000)]

d)

[x%3=0 for x in range(1, 1000)]

146.

Write a list comprehension equivalent for the Python code shown below.

a)

[i for i in range(1, 100) if int(i*0.5)==(i*0.5)]

b)

[i for i in range(1, 101) if int(i*0.5)==(i*0.5)]

c)

[i for i in range(1, 101) if int(i*0.5)=(i*0.5)]

d)

[i for i in range(1, 100) if int(i*0.5)=(i*0.5)]

147.

Write a list comprehension to produce the list: [1, 2, 4, 8, 16, ..., 1024].

a)

[2**x for x in range(0, 10)]

b)

[2**x for x in range(11)]

c)

[2*x for x in range(0, 11)]

d)

[2*x for x in range(1, 11)]

148.

What will be the output of the following Python code?

a)

[‘good’, ‘oh’, ‘excellent’, ‘450’ ]

b)

[‘good’]

c)

[‘good’, ‘#450’]

d)

[‘oh!’, ‘excellent!’, ‘#450’]