wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basics

Total questions: 100

Worksheet time: 2hrs 27mins

Name
Class
Date
1.

If p=25 , what is p**2?

a)

50

b)

125

c)

600

d)

625

2.

Who developed python?

a)

Ritchie

b)

Bill gates

c)

Guido van Rossum

d)

Sunder

3.

Which character is used to denote long integer?

a)

D

b)

N

c)

LO

d)

L

4.

In Python script editor, the errors will be shown in ----- color in the IDLE window?

a)

green

b)

black

c)

red

d)

orange

5.

Which is known as simple assignment operator?

a)

==

b)

=

c)

+=

d)

#

6.

Python uses ------ to define program blocks.

a)

whitespace

b)

delimiter

c)

escape sequence

d)

curly braces

7.

Which function accepts all data as string or characters but not as numbers?

a)

int()

b)

output()

c)

input()

d)

print()

8.

Which of these is not a core data type?

a)

Lists

b)

Dictionary

c)

Tuples

d)

Class

9.

What is the output of the following code :

print 9//2

a)

4.5

b)

4.0

c)

4

d)

Error

10.

Who developed the Python language?

a)

Zim Den

b)

Guido van Rossum

c)

Niene Stom

d)

Wick van Rossum

11.

Which one of the following is the correct extension of the Python file?

a)

.python

b)

.p

c)

.py

d)

None of these

12.

Which of the following declarations is incorrect?

a)

_x = 2

b)

__x = 3

c)

__xyz__ = 5

d)

None of these

13.

Which of the following declarations is incorrect in python language?

a)

xyzp = 5,000,000

b)

x y z p = 5000 6000 7000 8000

c)

x,y,z,p = 5000, 6000, 7000, 8000

d)

x_y_z_p = 5,000,000

14.

What will be the output of this statement?

>>>"a"+"bc"

a)

a+bc

b)

a bc

c)

abc

d)

a

15.
What is the output from the following code?print ("hello world")
a)
Hello World
b)
hello world
c)
print hello world
16.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
17.
Why do we use variables in programming?
a)
edit data
b)
store data
c)
integer
d)
to look good
18.

Which of these operators means EQUAL TO?

a)

'='

b)

'=>'

c)

'<='

d)

'=='

19.
What would amount equal in this piece of code:

amount = 2 + 5 * 2
a)
12
b)
9
c)
14
d)
5
20.

What is the output of range(1,10)

a)

0123456789

b)

123456789

c)

1 to 10

d)

012345

21.

Choose the correct declaration of a float variable with the value 3.14

a)

pi = "3.14"

b)

pi = int(3.14)

c)

pi = 3.14

d)

float pi = 3.14

22.

What is the final result of the expression 4 + 5 * 3?

a)

27

b)

12

c)

19

d)

21

23.

What is the final result of the expression 7 / 3 + 6?

a)

0

b)

8.33333333

c)

8

d)

.777777777778

24.

What does the following code print?

x = 3.4

y = 1

print int(x)

print x + y

a)

3.4

4.4

b)

3

4.4

c)

3

4

d)

The code causes an error

25.

What is the final result of the expression 2**3?

a)

6

b)

8

c)

2

d)

That is not a valid Python expression.

26.

What is the operator below called?

%

a)

Exponent

b)

Modulus

c)

Divide

d)

Percent

27.

print(9//3,9/3)

a)

3 3.3

b)

3.3 3

c)

3.0 3.3

d)

3.3 3.3

28.

Valid operation?

a)

'2'-'1'

b)

'third'*'2'

c)

'sum'**3

d)

"2"+"1"

29.

What is the output of this expression, 3*1**3?

a)

3

b)

21

c)

9

d)

33

30.

print(1.1+2.2==3.3)

a)

True

b)

False

c)

Error

d)

3.3

31.

Suppose the following statements are executed:

a = 100 b = 200

What is the value of the expression a and b?

a)

200

b)

100

c)

0

d)

False

32.

What is the output of “hello”+1+2+3 ?

a)

hello123

b)

hello

c)

Error

d)

hello6

33.

str1 = "My salary is 7000"; str2 = "7000" print(str1.isdigit()) print(str2.isdigit())

a)

False True

b)

False False

c)

True False

d)

True     True

34.

print(-18//-2)

print(18//2)

print(18/2)

print(18%2)

print(str(18/2))

find output

a)

9.0

9

9.0

0

9.0

b)

9

9

9.0

0

"9.0"

c)

9

9

9.0

0

9.0

d)

9

9

9.0

0

90

35.

x = 10

y = 50

if x ** 2 > 100 and y < 100:

print(x, y)

find output

a)

NONE

b)

Error

c)

10,50

d)

100

36.

4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators?a = 4

b = 11

print(a | b)

print(a >> 2)

a)

15

0

b)

0

15

c)

15

1

d)

1

15

37.

y = 10

x = y += 2

print(x)

a)

12

b)

10

c)

0

d)

Error

38.

print(int(12.53))

print(round(12.53))

print(round(12.36,1))

a)

13

12

12.4

b)

12

13

12.4

c)

12

13

12.3

d)

error

39.

Single line comment Symbol?

a)

//

b)

/

c)

$

d)

#

40.

Choose the correct function to get the character from ASCII number

a)

 ascii(number)

 

b)

 char(number)

 

c)

chr(number)

d)

ord(number)

41.

str1 = 'Welcome'

print (str1[:6] + ' PYnative')

a)

Welcome PYnative

 

b)

WelcomPYnative

 

c)

Welcom PYnative

 

d)

WelcomePYnative

42.

The function pow(x,y,z) is evaluated as:

a)

(x**y)**z

b)

(x**y) / z

c)

(x**y) % z

d)

(x**y)*z

43.

‘If’ is a decision making statement

a)

TRUE

b)

FALSE

44.
The second part of if, that is executed when the condition is false
a)
if
b)
else
c)
for
d)
input
45.

What is the output?

a)

more than 7

b)

more than 23

c)

spam

d)

7

46.

Which symbol means "not equal to"?

a)

==

b)

<=

c)

>=

d)

!=

47.

If you want to test more than one condition (chained condition), what do you use after if statement?

a)

elif

b)

else

c)

ifif

d)

else if

48.

Which character must be at the end of the line for if?

a)

:

b)

;

c)

.

d)

{

49.
What symbol do you use to make a comment in Python?
a)
@
b)
¬
c)
;
d)
#
50.

What does the = = symbol mean in Python?

a)

Equal to or shows equality

b)

Not Equal

c)

Code that will be skipped

d)

End of clause

51.

What is the Python built-in function used to display numbers and text on the screen?

a)

print

b)

input

c)

output

d)

command

52.
What will be printed to the screen?
a)
Nothing
b)
Success
c)
Failure
d)
Success
 Failure
53.
What will be printed to the screen?
a)
Success
b)
Failure
c)
Part of the way there!
d)
Nothing
54.
What will be printed to the screen?
a)
Failure
b)
Part of the way there!
c)
Success
d)
Nothing
55.
What will be printed to the screen?
a)
Nothing
b)
Success
c)
Part of the way there!
d)
Failure
56.

What will be the output of the code displayed?

(a)  

57.

What is the output from the following code?

(a)  

58.

What is the output from the following code?

(a)  

59.

What is the output from the following code?

(a)  

60.

What is the output of the following code?

(a)  

61.

What is the output from the following code?

(a)  

62.

What is the output from the following code?

(a)  

63.

What is the missing line of code?

a)

new = chr(new)

b)

new = ord(new)

c)

new = chr(letter)

d)

print new

64.

What is the missing line of code?

a)

if new > ord('z'):

b)

If new =< ord('z'):

c)

if new > chr('z'):

d)

else next:

65.

The following message was encoded using a Rotating Cipher (Ceaser shift).

transfer the amount on wednesday

and sent as...

ywfsxjw ymj ts bjisjxifd

What was the key used to encrypt the message?

(a)  

66.
a)

AB

['ab', 'cd']

b)

AB

CD

['ab', 'cd']

c)

['ab', 'cd']

d)

Error

67.
a)

['ab', 'cd','AB']

b)

['ab', 'cd','AB' , 'CD']

c)

['ab', 'cd']

d)

Infinite Loop

68.
a)

SyntaxError

b)

1 2

c)

1 2 3

d)

1

69.
a)

123

b)

1 2 3

c)

TypeError

d)

1

2

3

70.
a)

1234

b)

4321

c)

Error

d)

1 2 3 4

71.

What is the output of the below program


for i in (1, 2, 3, 4)[::-1]:

print(i,end='')

a)

1234

b)

4321

c)

Error

d)

1 2 3 4

72.

What is the output of the below program


for i in {1, 2, 3, 4}[::-1]:

print(i,end='')

a)

1234

b)

4321

c)

Error

d)

1 2 3 4

73.

What is the output of the below program


my_string = "Python"

for i in my_string:

print(i, end =" ")

a)

Python

b)

P y t h o n

c)

P

d)

Error

74.

What is the output of the below program


my_string = "Python"

while i in my_string:

print(i, end =" ")

a)

Python

b)

P y t h o n

c)

P

Error

d)

Error

75.
a)

0 1 2 3 0

b)

0 1 2 0

c)

0 1 2

d)

Error

76.

What is the output of the following?


my_string = 'geeksforgeeks'

for i in range(my_string):

print(i)

a)

geeksforgeeks

b)

None

c)

Error

d)

0 1 2 3 … 12

77.
a)

The program will loop indefinitely

b)

The value of number will be printed exactly 1 time

c)

The while loop will never get executed

d)

The value of number will be printed exactly 5 times

78.
a)

12

b)

9

c)

7

d)

8

79.
a)

4

b)

0

c)

7

d)

16

80.
a)

Number: 10

b)

Number: number

c)

Number: 0

d)

Number: 11

81.
a)

5 4 3 2 1

b)

-4 -3 -2 -1 0

c)

-5 -4 -3 -2 -1

d)

This is an infinite loop, so nothing will be printed

82.
a)

var1 = -2, var2 = 0

b)

var1 = 0, var2 = -2

c)

var1 = 0, var2 = -1

d)

This is an infinite loop, so nothing will be printed

83.

How many asterisks will be printed when the following code executes?


for x in [0, 1, 2, 3]:

for y in [0, 1, 2, 3, 4]:

print('*')

a)

0

b)

4

c)

5

d)

20

e)

This is an infinite loop, so nothing will be printed

84.
a)

n starts at 10 and is incremented by 1 each time through the loop, so it will always be positive.

b)

answer starts at 1 and is incremented by n each time, so it will always be positive.

c)

You cannot compare n to 0 in the while loop. You must compare it to another variable.

d)

In the while loop body, we must set n to False, and this code does not do that.

85.

Which type of loop can be used to perform the following iteration: You choose a positive integer at random and then print the numbers from 1 up to and including the selected integer.

a)

a for-loop or a while-loop

b)

only a for-loop

c)

only a while-loop

86.
a)

Current Letter : P

b)

Current Letter : t

c)

Current Letter : h

d)

Current Letter : o

87.
a)

x = 2; y = 5

b)

x = 5; y = 2

c)

x = 4; y = 3

d)

x = 4; y = 2

88.
a)

The program has five iterations but does not print anything.

.

b)

The loop will repeat forever and results in an infinite loop.

c)

The program compiles and prints "1 2 3 4 5 Blastoff!" where each space is a new line.

d)

The program compiles and prints "5 4 3 2 1 Blastoff!" where each space is a new line.

89.
a)

nothing prints

b)

'Done!'

c)

'#'

d)

'>'

90.

The for loop is not an “indefinite” loop because…

a)

it loops through a known set of items so it runs through as many iterations as there are items in the set.

b)

it loops until some condition becomes True.

c)

it loops until some condition becomes False.

d)

it loops until it reaches a "break" statement.

91.

What is the final value of i when you execute this block of code?

a)

8

b)

10

c)

9

d)

7

92.

How many times will the program go through the while statement if i = 1?

a)

10

b)

9

c)

8

d)

7

93.

What is the output for this block of code on the 3rd pass on the for loop?

a)

2: 4

b)

2: 5

c)

2: 3

d)

2: 2

94.

Will the value of n change when you execute this block of code?

a)

Yes

b)

No

c)

Not sure

d)

I need more information

95.

How many unique outputs will this block of code generate?

a)

15

b)

25

c)

50

d)

75

96.

Read carefully: when will you encounter an output of "2 : 2 : 2" if you run this block of code?

a)

25th pass

b)

17th pass

c)

9th pass

d)

2nd pass

97.

Which among these numbers should you enter to get an angry reaction from the block of code?

a)

12

b)

16

c)

18

d)

21

98.

When will this block of code stop executing?

a)

If you give what it wants

b)

If you give what it needs

c)

If you tell your darkest secret

d)

If you give it an odd number

99.

What will be the reaction returned if you entered 754?

a)

(人◕ω◕)

b)

(`Д´)

c)

(◕‿◕✿)

d)

(✪‿✪)

100.

After inputting '3058', the program said, (人◕ω◕) thank you!

What will the program show next?

a)

continue

b)

(nothing)

c)

Give me an even number:

d)

(人◕ω◕) thank you!