wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Fundamentals- 02

Total questions: 32

Worksheet time: 34mins

Name
Class
Date
1.

b = [11,13,15,17,19,21]

What is output for − print(b[::2])

a)

[19,21]

b)

[11,15]

c)

[11,15,19]

d)

[13,17,21]

2.

When the given code is executed how many times ' 'you are learning python ' ' will be printed.

a)

a = 0

while a<10:

print(''you are learning python'')

pass

b)

9

c)

10

d)

11

e)

Infinite number of times

3.

What is the output of the following code?

var1 = 1

var2 = 2

var3 = "3"


print(var1 + var2 + var3)

a)

6

b)

33

c)

123

d)

Error. Mixing operators between numbers and strings are not supported

4.

What is the output of the following code?

sampleList = ["Jon", "Kelly", "Jessa"]

sampleList.append("Scott")

print(sampleList)

a)

[‘Jon’, ‘Kelly’, ‘Scott’, ‘Jessa’]

b)

[‘Jon’, ‘Kelly’, ‘Jessa’, ‘Scott’]

c)

[‘Jon’, ‘Scott’, ‘Kelly’, ‘Jessa’]

d)

The program executed with errors

5.

What is the output of the following


x = 36 / 4 * (3 + 2) * 4 + 2

print(x)

a)

182.0

b)

37

c)

117

d)

The Program executed with errors

6.

What is the output of the following code?


p, q, r = 10, 20 ,30

print(p, q, r)

a)

10 20

b)

10 20 30

c)

30 20 10

d)

Error: invalid syntax

7.

What is the output of the following code?


valueOne = 5 ** 2

valueTwo = 5 ** 3


print(valueOne)

print(valueTwo)

a)

10

15

b)

25

125

c)

Error: invalid syntax

8.

What is the output of the following code?

var = "James" * 2 * 3

print(var)

a)

JamesJamesJamesJamesJamesJames

b)

JamesJamesJamesJamesJames

c)

Error: invalid syntax

9.

What is the output of the following code?

var= "James Bond"

print(var[2::-1])

a)

Jam

b)

dno

c)

maj

d)

dnoB semaj

10.

What is the output of the following code?


str = "pynative"

print (str[1:3])

a)

py

b)

yn

c)

pyn

d)

yna

11.

A line of text that Python won't try to run as code

a)

comment

b)

variable

c)

modulue

d)

boolean

12.

Symbol used for modulus

a)

%

b)

&

c)

#

d)

**

13.

A data type that can have one of two values: True or False

a)

boolean

b)

Integer

c)

String

d)

Complex

14.

102 = 100

Which of the following is used in Python to calculate ten squared?

a)

10 ** 2

b)

10 % 2

c)

10 * 2

d)

10 ** 10

15.

A data type consisting of numbers, letters and symbols.

a)

String

b)

Float

c)

Integer

d)

Boolean

16.

What is the position of the name 'Paula' in the following array:

names = ["Paul","Phillip","Paula","Phillipa"]

a)

0

b)

2

c)

1

d)

3

17.

which of the following statements can be used to return the length of the given String, str?

a)

size(str)

b)

str.size()

c)

len(str)

d)

str._len_()

18.

str='Hello World'


print (str.find('o'))

a)

4, 7

b)

7

c)

4

d)

2

19.

str='Tech Beamers'

print (str[4:9])

a)

Beamers

b)

Beame

c)

Beam

d)

Beamer

20.

What is the output when following statement is executed?

print ('Tech' 'Beamers')

a)

Tech Beamers

b)

TechBeamers

c)

Beamers

d)

Tech

21.

Which of the answers would print the output as given below?


C:\Common\TestString.doc

a)

str='''C:\Common\testString.doc'''

print (str)

b)

str='C:\Commo\n\TestSt\ring.doc'

print (str)

c)

str='C:\Common\TestStri\ng.doc'

print (str)

d)

str='C:\Common\TestString.doc'

print (str)

22.

What is the output of the following script when age = 50:

if age > 40:


if age > 60:


print('Turning old')


else:


print('Middle age')


else:


print('Young age')

a)

Turning old

b)

Middle age

c)

Turning old

Middle age

d)

Young age

23.

Which of the following is a valid variable name in Python?

a)

do it

b)

do+1

c)

1do

d)

All of the above

e)

None of the above

24.

What does the following print?

x = 10 / 4

y = 5 / 2.0

print (x + y)

a)

4

b)

5.0

c)

4.5

d)

7

e)

None of the above

25.

Across how many lines will the following program’s output appear?

print ("how\nnow\tbrown/ncow?")

a)

2

b)

4

c)

3

d)

1

e)

None of the above

26.

Which of the following Boolean expression(s) implement the following statement?

x and y are not equal to zero, and they are either both positive or both negative (read carefully)

a)

( x < 0 and y < 0 ) or ( x > 0 and y > 0 )

b)

( x * y ) > 0

c)

( x < 0 or x > 0 ) and ( y < 0 or y > 0 )

d)

Two of the above are correct

e)

All of the above are correct

27.

Given the variables declared below, which expression evaluates to True?

a = 3

txt = "fun"

limit = 10

words = 5

a)

a == limit - words

b)

not ( words < limit )

c)

( a > limit ) or ( len( txt ) < words )

d)

words * a < limit

e)

( len( txt ) > 0 ) and ( limit - words < a )

28.

What kind of statement is the IF statement?

a)

Concurrent

b)

Assignment

c)

Conditional Statement

d)

Selected assignment

29.

Which of the following commands will create a list?

a)

list1 = list()

b)

list1 = []

c)

list1 = list([1, 2, 3])

d)

all of the mentioned

30.

What is the output when we execute list("hello")?

a)

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

b)

[‘hello’]

c)

[‘llo’]

d)

[‘olleh’]

31.

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

a)

Error

b)

None

c)

25

d)

2

32.

What will be the output of the following Python code?


list("a#b#c#d".split('#'))

a)

[‘a’, ‘b’, ‘c’, ‘d’]

b)

[‘a b c d’]

c)

‘a#b#c#d’]

d)

[‘abcd’]