wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

python

Total questions: 73

Worksheet time: 1hrs 13mins

Name
Class
Date
1.

A store your program must use as an identifier to keep track of a value is called a

a)

Algorithm

b)

Variable

c)

Program

d)

Assignment

2.

Which symbol assigns a value to a variable?

(a)  

3.

Which of the following would be an example of a string variable:

a)

ValidInput = False

b)

GuessCount = 100

c)

Name = "Bilbo"

d)

Pi = 3.14159265359

4.

To execute a Python program, you need a Python interpreter.

a)

True

b)

False

5.

Which of the following would be an example of a float variable:

a)

ValidInput = False

b)

GuessCount = 100

c)

Name = "Bilbo"

d)

Pi = 3.14159265359

6.

The rules for how programming languages statements can be assembled is known as

a)

Variable

b)

Algorithm

c)

Syntax

d)

Debugging

7.

Which of the following would be an example of an integer variable:

a)

ValidInput = False

b)

GuessCount = 100

c)

Name = "Bilbo"

d)

Pi = 3.14159265359

8.

What is the greater than symbol:

(a)  

9.

Python is the fastest growing programming language:

a)

True

b)

False

10.

What would be the result of 3 ** 3

(a)  

11.

What would be the result of 9 // 7

(a)  

12.

What would be the reult of 9 % 7

(a)  

13.

Text to be output to the screen should be enclosed by " "

a)

True

b)

False

14.

The Python IDE colour codes sections of your code to make it easier to debug

a)

True

b)

False

15.

A: Strings can be changed during execution

B. Strings can be enclosed within single, double or even triple quotes

C. Strings are immutable

a)

A,B & C are True

b)

A,B are True but C is False

c)

B, C are True but A is False

d)

A,C are True but B is False

16.

Find the output of the following code:

>>>str1='Save Soil'

>>>str1.isalnum( )

a)

Save Soil

b)

True

c)

False

17.

Identify the string membership operators of Python

a)

in, not in

b)

like, not like

c)

as, not as

d)

between, not between

18.

Which is the powerful function used for formatting strings?

a)

chr( )

b)

format( )

c)

title( )

d)

capitalize( )

19.

The title( ) function

a)

assigns title

b)

returns the title of the file

c)

returns string in title case

20.

Predict the output:

>>>str1="Rajathi Raja"

>>>print(str1.count('Raja'))

a)

1

b)

2

c)

Error

d)

Raja

21.

Match the following:

1. \n A) Carriage return

2. \v B) BackSpace

3. \b C) new line

4. \r D) Vertical tab

a)

1-C, 2-D, 3-B, 4-A

b)

1-A, 2-C, 3-B, 4-D

c)

1-C, 2-D, 3-A, 4-B

d)

1-C, 2-A, 3-B, 4-D

22.

Predict the output:

>>>saint="Thiruvalluvar"

>>>print(saint[5:])

a)

valluvar

b)

Thiruvalluvar

c)

uvalluvar

d)

Thiru

23.

MATCH THE FOLLOWING:

1. concatenation A) +=

2. Append B) [ ]

3. String Slicing C) *

4. Repeating D) +

a)

1-B. 2-A, 3-C, 4-D

b)

1-D. 2-A, 3-B, 4-C

c)

1-A,2-B,3-C,4-D

d)

1-A,2-D,3-C,4-B

24.

s="welcome"

print( s. center (15,'*'))

a)

***welcome***

b)

****welcome****

c)

****welcome***

d)

undefine function center

25.

The unexpected event happened during program execution should be handled by

a)

EXCEPTION

b)

EXPERIMENT

c)

ASSERTION

d)

EXTRAORDINARY

26.

try:

a=int(input("\n Enter a Value"))

b=int(input("\n Enter a Value "))

c=a/b

print (c)

except:

print("\n Something Went Wrong")


Assume a = 10 and b = 5, then the output will be

a)

5.0

b)

Something Went Wrong

c)

Arithmetic Error

d)

2.0

27.

Exception disrupts the

a)

Normal flow of the program

b)

Abnornal flow of the program

c)

Hard Disk

d)

None of the Above

28.

The suspicious code is put inside the

a)

Try Block

b)

Finally Block

c)

Else Block

d)

Except Block

29.

________ statement can also be used without specifying Exception.

a)

Try

b)

Finally

c)

Except

d)

Else

30.

try:

a=10/5

print (a)

except ArithmeticError:

print ("This statement is raising an exception" )

finally:

print (" final block executed " )

a)

2.0

final block executed

b)

This statement is raising an exception

final block executed

c)

final block executed

d)

2.0

31.

An exception can be manually triggered by the command

a)

raise

b)

try

c)

except

d)

trigger

32.

User defined Exceptions are created from the _________ Parent Class

a)

Exception

b)

Except

c)

Handler

d)

User Defined Exception

33.

How many except statements can a try-except block have?

a)

zero

b)

one

c)

more than one

d)

more than zero

34.

When will the else part of try-except-else be executed?

a)

a) always

b)

b) when an exception occurs

c)

c) when no exception occurs

d)

d) when an exception occurs in to except block

35.

Is the following Python code valid?


try:

# Do something

except:

# Do something

else:

# Do something

a)

no, there is no such thing as else

b)

no, else cannot be used with except

c)

no, else must come before except

d)

yes

36.

What will be the output of the following Python code?


lst = [1, 2, 3]

lst[3]

a)

a) NameError

b)

b) ValueError

c)

c) IndexError

d)

d) TypeError

37.

What will be the output of the following Python code?


lst = [1, 2, 3]

lst[3]

a)

a) NameError

b)

b) ValueError

c)

c) IndexError

d)

d) TypeError

38.

Which keyword is used for function?*

a)

define

b)

fun

c)

def

d)

function

39.

Which of the following items are present in the function header?

a)

function name

b)

parameter list

c)

return value

d)

Both A and B

40.

If the return statement is not used inside the function, the function will return:

a)

0

b)

None

c)

Null

d)

Arbitary value

41.

What is a recursive function?

a)

A function that calls other function.

b)

A function which calls itself.

c)

Both A and B

d)

None of the above

42.

Which of the following function headers is correct?*

a)

def fun(a = 2, b = 3, c)

b)

def fun(a = 2, b, c = 3)

c)

def fun(a, b = 2, c = 3)

d)

def fun(a, b, c = 3, d)

43.

In which part of memory does the system store the parameter and local variables of a function call?

a)

heap

b)

stack

c)

Uninitialized data segment

d)

None of the above

44.

How is a function declared in Python?*

a)

def function function_name():

b)

declare function function_name():

c)

def function_name():

d)

declare function_name():

45.

Which one of the following is the correct way of calling a function?

a)

function_name()

b)

call function_name()

c)

ret function_name()

d)

function function_name()

46.

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

a)

array()

b)

sqrt()

c)

factorial()

d)

print()

47.

What will be the output of the following Python expression? round(4.576)

a)

4.5

b)

5

c)

4

d)

4.6

48.

What will be the output of the following Python expression? round(4.5676,2)

a)

4.5

b)

4.6

c)

4.57

d)

4.56

49.

A Python module is a file with the _____ file extension that contains valid Python code.

a)

.pym

b)

.pymodule

c)

.module

d)

.py

50.

What is returned by math.ceil(3.4)?

a)

3

b)

4

c)

4.0

d)

3.0

51.

Which statement is correct to import all modules from the package

a)

from package import all

b)

from package import *

c)

from package include all

d)

from package include *

52.

(a)   is a string literal denoted by triple quotes for providing the specifications of certain program elements.

53.

Which of the following is not a valid namespace?

a)

Global namespace

b)

Public namespace

c)

Built-in namespace

d)

Local namespace

54.

What is the order of namespaces in which Python looks for an identifier?

a)

Python first searches the global namespace, then the local namespace and finally the built-in namespace

b)

Python first searches the local namespace, then the global namespace and finally the built-in namespace

c)

Python first searches the built-in namespace, then the global namespace and finally the local namespace

d)

Python first searches the built-in namespace, then the local namespace and finally the global namespace

55.

The collection of modules and packages that together cater to a specific type of applications or requirements, is called______

a)

module

b)

library

c)

classes

d)

documentation

56.

The help statement display ___ from a module.

a)

constants

b)

functions

c)

classes

d)

docstrings

57.
a)

10#40#70#

b)

30#40#50#

c)

50#60#70#

d)

40#50#70#

58.
a)

a=10

b)

a=20

c)

syntax error

d)

value error

59.
4 lines
60.
4 lines
61.
What is a variable?
a)
A box(memory location) where you store values
b)
a type of graphics
c)
Data type
d)
a type of memory
62.
What symbol is used in python to assign values to a variable?
a)
equals =
b)
plus + 
c)
forward slash /
d)
asterisk *
63.

What will be the output?

name = "Dave"

print (name)

a)

Dave

b)

'Dave'

c)

name

d)

(name)

64.
When you have an error in your code what is the term to summarise finding and fixing that error?
a)
Error checking
b)
Debugging
c)
Syntax finder
d)
Error finder
65.
A syntax error means your code has a 'grammar' mistake or you used symbols/operations incorrectly
a)
True
b)
False
66.
Which statement correctly assigns the string "Tanner" to the variable name?
a)
name  = print( "Tanner")
b)
input("Tanner")
c)
name = "Tanner"
d)
name = input("Tanner")
67.
What does the term 'debug' mean?
a)
Identify errors and fix them.
b)
Making a calculation
c)
A set of instructions
d)
Looking at code
68.
What does the print function do in python?
a)
It's a variable.
b)
It can input data.
c)

It displays an output

d)
It loops the code.
69.
In the following code, "city" is an example of a what?
a)
List
b)
Loop
c)
Variable
d)
Array
70.

What is the output from the following code?

print ("hello world")

a)
Hello World
b)
hello world
c)
print hello world
71.

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

a)

print

b)

input

c)

output

d)

command

72.

The punctuation requirements for printing a string in Python are:

a)

( ) , ! and " "

b)

( ) and !

c)

( ) and " "

d)

" " and !

73.

What will be the output?

name = "Dave"

print ("name")

a)

Dave

b)

"Dave"

c)

name

d)

"name"