wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Pre-Assessement | Python Essentials | FT Batch 3 | Paramesh G

Total questions: 50

Worksheet time: 30mins

Name
Class
Date
1.

What is output by the following? Assume the user enters 3 and 9

a = input("Enter a number: ")

b = input ("Enter a number: ")

print ("Values: " + a + b)

a)

Values: 39

b)

Values: 12

c)

12

d)

39

2.

Consider the following code:

x = input ("What year is it?")

print(x)

The Value stored in x is:

a)

a string

b)

an int

c)

stored in secondary memory

d)

a program

3.

else: is used

a)

to give an extra condition

b)

to provide an output when the other conditions are false

c)

because it is required

d)

if we do not use it, it gives error

4.

What would the program display if you ran this code and entered 2 and then 3 when prompted?

a)

The total is 5.

b)

The total is 23.

c)

The total is 6.

d)

An error.

5.

Consider the file "d://test.txt" with the contents as given below:

Hi there,

I am loving Python.

Python is Simple

Choose the correct output from the above code snippet from the given options:

a)

Read String is : Hi there

b)

Read String is : Hi there,

c)

Syntax error

d)

Hi there,

I am loving Python.

Python is simple.

6.

Consider a list, fruits=["Mango", "Banana", "Guava", "Strawberry"]. Match the following:

a. fruits[-4:]

b. fruits[-2:]

c. fruits[-4:-1]

d. fruits[1:4]

Select the correct answer for a, b, c & d

a)

['Banana', 'Guava', 'Strawberry']

b)

['Mango', 'Banana', 'Guava', 'Strawberry']

c)

['Mango', 'Banana']

d)

['Mango', 'Banana', 'Guava']

e)

['Guava', 'Banana', 'Mango']

7.

What gets printed?

names = ['Amir', 'Barry', 'Chales', 'Dao']

print(names[-1][-1])

a)

A

b)

r

c)

Amir

d)

Dao

e)

o

8.

What gets printed from the above piece of code?

a)

11

b)

12

c)

21

d)

22

e)

33

9.

List a is defined as follows:

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

Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:

a)

a[2:2] = []

b)

del a[2]

c)

a[2] = []

d)

a[2:3] = []

e)

a.remove(3)

10.

Which of the following are true of Python dictionaries:

a)

Dictionaries can be nested to any depth.

b)

Dictionaries are accessed by key.

c)

All the keys in a dictionary must be of the same type.

d)

Dictionaries are mutable.

e)

A dictionary can contain any object type except another dictionary.

11.

Which of the following is not a valid way to define this dictionary in Python:

a)

d = dict([

('foo', 100),

('bar', 200),

('baz', 300)

])

b)

d = {}

d['foo'] = 100

d['bar'] = 200

d['baz'] = 300

c)

d = dict(foo=100, bar=200, baz=300)

d)

d = {'foo': 100, 'bar': 200, 'baz': 300}

e)

d = { ('foo', 100), ('bar', 200), ('baz', 300) }

12.

You have the following dictionary definition:


d = {'foo': 100, 'bar': 200, 'baz': 300}


What method call will delete the entry whose value is 200?

a)

delete d('bar')

b)

d.pop("bar")

c)

d.remove("bar")

d)

None of the above

13.

What would be the output of the following code snippet?


a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}

d_items = a_dict.items()

print(d_items)

a)

('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')

b)

dict_items([('color'), ('fruit'), ('pet')])

c)

[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]

d)

dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])

14.

Which of the following is the output of the below Python code?


var1 = lambda var: var * 2

ret = lambda var: var * 3

result = 2

result = var1(result)

result = ret(result)

result = var1(result)

print(result)

a)

24

b)

12

c)

7

d)

36

e)

48

15.

Which of the following is the output of the below Python code?

[Note: Python 2.7.5 and above]


mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']

print(mylist[int(-1/2)])

a)

b

b)

bbb

c)

'bbb'

d)

a

16.

What is the correct syntax to output the type of a variable or object in Python?

a)

print(typeof(x))

b)

print(typeof x)

c)

print(typeOf(x))

d)

print(type(x))

17.

Which of the following is the output of the instructions given below?


mylist=[1, 5, 9, int('0')]

print(sum(mylist))

a)

16

b)

5

c)

1

d)

15

18.

Which of the following statements best describes the behavior of the random.shuffle(mylist) as being used in the below code fragment?


import random

mylist = [10, 20, 30]

random.shuffle(mylist)

print(mylist)

a)

return a list where elements 10, 20 and 30 would be at random positions.

b)

It'll not modify the list. This function is just a placeholder and yet to be implemented.

c)

shuffle the elements of the list in-place.

d)

shuffle the elements for the no. of times equal to the size of the list.

19.

Which of these collections defines a SET?

a)

{"apple", "banana", "cherry"}

b)

{"name": "apple", "color": "green"}

c)

("apple", "banana", "cherry")

d)

["apple", "banana", "cherry"]

20.

How do you start writing a for loop in Python?

a)

for x in y:

b)

for each x in y:

c)

for x > y:

21.

How do you create a variable with the floating number 2.8?

a)

x=float(2.8)

b)

x=2.8

c)

both option are correct

22.

Which one is NOT a legal variable name?

a)

my_var

b)

my-var

c)

Myvar

d)

-myvar

23.
What does debugging mean?
a)
Fixing errors in your code
b)
Specific actions for the computer to do
c)
Telling a computer what to do
d)
Eating bugs
24.
What is coding?
a)
A type of fish.
b)
Telling a computer what to do.
c)
It doesn't exist
d)
An error in your code
25.

Full form of UI

a)

User Interface

b)

Underrated interface

c)

Under indent

d)

Upper Indent

26.

What will be the value of the following Python expression?

4 + 3 % 5

a)

7

b)

2

c)

4

d)

1

27.

What is the order of precedence in python?

a)

Exponential, Parentheses, Multiplication, Division, Addition, Subtraction

b)

Exponential, Parentheses, Division, Multiplication, Addition, Subtraction

c)

Parentheses, Exponential, Multiplication, Division, Subtraction, Addition

d)

Parentheses, Exponential, Multiplication, Division, Addition, Subtraction

28.

Which of the following is an invalid statement?

a)

abc = 1,000,000

b)

a b c = 1000 2000 3000

c)

a,b,c = 1000, 2000, 3000

d)

a_b_c = 1,000,000

29.

What is the ASCII value of 'm' ?

a)

110

b)

109

c)

77

d)

76

30.

What is the result of the following condition if:

A = 30

B = 21

C = 71

B != A or C < A

a)

True

b)

False

31.
What will be printed to the screen?
a)
Success
b)
Failure
c)
Part of the way there!
d)
Nothing
32.
What will be printed to the screen?
a)
Failure
b)
Part of the way there!
c)
Success
d)
Nothing
33.

What is the output from the following code?

(a)  

34.

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

35.

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:

36.

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

37.

What is the output of the program above

a)

10

b)

15

c)

18

d)

17

e)

16

38.

fruit1="kiwi"

fruit2="strawberry"

print(len(fruit1))

print(len(fruit2))

a)

kiwi and strawberry

b)

4

10

c)

4 10

d)

410

39.
How many times will Boo print?
a)
none
b)
4
c)
5
d)
1
40.

The process of creating a function is as follows

1. Use the keyword def to declare the function

2. Follow with defining the function name

3. Add parameters to the function: they should be within the parentheses() of the function.

4. End this line with a colon after the parenthesis.

5. Indent and then add the statements that the functions should execute

6. Include a return statement if the function should output something. Without the return statement, your function will return an object  - None

What is missing from this function?

a)

return value statement

b)

Variable

c)

Function definition

d)

Parameters

41.

The parameters could be a

a)

Variable

b)

Literal

c)

Expression

d)

Function

42.
What will print?
a)
nothing
b)
sayHi()
c)
an error message
d)
hi there
43.

      Predict the output

a)

stop

slow

go

b)

slow

c)

None

d)

go

44.

Select which is true for Python function

a)

A Python function can return only a single value

b)

A function can take an unlimited number of arguments

c)

A Python function can return multiple values

d)

Python function doesn’t return anything unless and until you add a return statement

45.

Predict the output.

Note: end=' ' is a single space

a)

('cls', 'XII') ('test', 'UT1')

b)

'cls' 'test'

c)

'XII' 'UT1'

d)

{'cls': 'XII'} {'test': 'UT1'}

46.

What will be the output of the following Python code?print("abc.DEF". capitalize())

a)

Abc.def

b)

abc.def

c)

ABC.DEF

d)

Abc.Def

47.

Is this code valid in Python?

>>> m=6,7,8,9

>>> m

a)

No, many values will unpack

b)

Yes, 6 will be printed

c)

Yes, (6,7,8,9) will be printed

d)

Yes, [6,7,8,9] will be printed

48.

What will be the output of the following Python expression if x=56.236?

print("%.2f"%x)

a)

56.236

b)

56.23

c)

56.0000

d)

56.24

49.

Which type of Programming does Python support?

a)

Object Oriented Programming

b)

Structured Programming

c)

Functional Programming

d)

All of the above

50.

Which of the following is true for variable names in Python?

a)

underscore and ampersand are the only two special characters allowed

b)

unlimited length

c)

all private members must have leading and trailing underscores

d)

none of these