wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming with modules

Total questions: 61

Worksheet time: 46mins

Name
Class
Date
1.

What is a library in python?

a)

COLLECTION OF FILES

b)

COLLECTION OF MODULES

c)

IT IS SUBPROGRAM

d)

NAME OF A FILE

2.

exp(),floor()belongs which module?

a)

cmath.py

b)

urlib.py

c)

math.py

d)

statistics.py

3.

Which operator is used in python to import all modules from package

a)

-- operator

b)

+ operator

c)

* operator

d)

----> operator

4.

A variable defined inside the def() we called as

a)

Global

b)

enclosing

c)

local

d)

local to def()

5.

What is the output of the following program :

y = 8

z = lambda x : x * y

print z(6)

a)

48

b)

22

c)

8

d)

24

6.

This program will produce

a)

a random number between 10 and 100 (including 10 but not 100) always in increments of 10

b)

a random number between 10 and 100 (including 10 and 100) always in increments of 10

c)

10 random numbers between 10 and 100 (including 10 and 100)

d)

10 random numbers between 10 and 100 (including 10 and not 100)

7.

This code is equivalent to

a)

random.randint(1,11)

b)

random.randint(1,10)

c)

random.randrange(1,11,1)

d)

random.randrange(1,10,1)

8.

Which file must be part of the folder containing python module files to make it importable python package?

a)

init.py

b)

_setup_.py

c)

_init_.py

d)

setup.py

9.

Which operator is used in python to import all modules from packages?

a)

. operator

b)

* operator

c)

-> symbol

d)

, operator

10.

__________ is a library used to create data structures and carry out scientific calculations.

a)

Python

b)

Numpy

c)

Pycharm

d)

Bar chart

11.

How to use numpy ?

a)

import numpy as np

b)

import pandas as pd

c)

import pyplot as plt

12.

Name the function used to create an array?

a)

np.aray()

b)

np.array()

c)

Np.array()

d)

np.arange()

13.

np.arange(2,8,1) ----> what output will be produced?

a)

2,3,4,5,6,7,8

b)

2,3,4,5,6,7,8,9

c)

2,3,4,5,6,7

d)

2,4,6,8

14.

np.array([4,7])

a)

[ 4 7 ]

b)

[ 4 5 6 7 ]

c)

[ 4 5 6 ]

d)

[ 1 2 3 4 5 6 7 ]

15.

names = np.array(["Reem" , "Salah" , "Haya" , "Maryam" , "Fatema"])

print(names([2,3,4]))

Mark the right output from the below options

a)

[ 'Haya' 'Maryam' 'Fatema' ]

b)

[ 'Maryam' 'Haya' 'Fatema' ]

c)

[ 'Reem' 'Salah' 'Fatema' ]

d)

[ 'Reem' 'Salah' 'Haya' ]

16.

names = np.array(["Reem" , "Salah" , "Haya" , "Maryam" , "Fatema"], dtype=object)

names[2] = "Omar"

print([names])

Mark the right output from the below options

a)

['Reem', 'Salah', 'Omar', 'Maryam', 'Fatema']

b)

[array(['Reem', 'Salah', 'Omar', 'Maryam', 'Fatema'], dtype=object)]

c)

['Reem' 'Salah' 'Omar' 'Maryam' 'Fatema']

d)

[['Reem' 'Salah' 'Omar' 'Maryam' 'Fatema']]

17.

Each location of an element in an array is called ______________

a)

Size

b)

Length

c)

Index

d)

Element

18.

Two dimensional arrays are also known as ______________

a)

Subscripts

b)

Matrices

c)

ndarray

d)

Vectors

19.

One dimensional arrays are also known as _____________

a)

Vectors

b)

ndarray

c)

Matrices

d)

Subscript

20.

_________________ returns the size of each element of array in bytes.

a)

len()

b)

itemsize

c)

shape

d)

type

21.

A=np.array([1,2,3,4],dtype=np.float64)

What is the itemsize of array 'A'?

a)

1

b)

4

c)

8

d)

16

22.

b=np.array([[1,2,3,4],[5,6,7,8],[10,11,12,13]])

Write the value of b[2,1].

a)

3

b)

6

c)

10

d)

11

23.

x=np.array([9,4,2,7])

y=x+5

a)

[14 9 7 12]

b)

[14,9 ,7, 12]

c)

[13 8 6 12]

d)

[13,8 ,6 ,12]

24.

_______________ function is used to change the dimension or shape of the array.(Select the code used for it.)

a)

shape

b)

reshape

c)

reshape()

d)

itemsize

25.

What multiplication sentence does this array show?

a)

4 X 8 = 32

b)

4 X 8 = 31

c)

5 X 8 = 32

d)

4 X 8

26.
Code repeated / looped until a condition has been met or a set number of times.
a)
Sequence
b)
Selection
c)
Iteration
d)
Variable
27.
Joining elements together to make a string is called what?
a)
Combining
b)
Connecting
c)
Concatenation
d)
Stringing
28.

What is a correct syntax to subtract the numbers from arr1 with the numbers from arr2?

a)

np.substract(arr1, arr2)

b)

np.min(arr1, arr2)

c)

np.sub(arr1, arr2)

d)

np.minus(arr1, arr2)

29.

What is the correct method for getting the Natural Logarithm (Logarithm at base e)?


arr = np.arange(1, 10)

a)

np.log(arr)

b)

np.loge(arr)

c)

np.natural(arr)

d)

np.ln(arr)

30.

When using the NumPy random module, how can you return a random number from 0 to 100?

a)

random.randint(100)

b)

random.rand()

c)

random.rand(100)

31.

When using the NumPy random module, how can you randomly shuffle an array?


arr = np.array([1, 2, 3, 4, 5])

a)

random.change(arr)

b)

random.shuffle(arr)

c)

random.rearrange(arr)

32.

When using the NumPy random module, how can you make sure you always get the same result?

a)

Use the random.seed() function to set a seed before running the other random functions

b)

Use the random.static() function to set an answer before running your random functions

c)

Use the random.change() function to change an answer before running your random functions

33.

What is a correct syntax to create a NumPy array?

a)

np.createArray([1, 2, 3, 4, 5])

b)

np.array([1, 2, 3, 4, 5])

c)

np.object([1, 2, 3, 4, 5])

34.

What is a correct syntax to print the numbers [3, 4, 5] from the array below:


arr = np.array([1,2,3,4,5,6,7])

a)

print(arr[2:5])

b)

print(arr[2:6])

c)

print(arr[2:4])

d)

print(arr[3:6])

35.

What is a correct syntax to return the shape of an array?

a)

shape(arr)

b)

arr.shape

c)

arr.shape()

36.

What is the correct syntax to reshape the array below into 4 arrays with 3 elements?


arr = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])

a)

newarr = arr.reshape(3, 4)

b)

newarr = arr.shape(3, 4)

c)

newarr = arr.reshape(4, 3)

d)

newarr = arr.shape(4, 3)

37.

How to use numpy ?

a)

import numpy as np

b)

import pandas as pd

c)

import pyplot as plt

38.

NumPY stands for?

a)

Numbering Python

b)

Number In Python

c)

Numerical Python

d)

None Of the above

39.

The most important object defined in NumPy is an N-dimensional array type called?

a)

ndarray

b)

narray

c)

nd_array

d)

darray

40.

What is the displayed value for Python coding below:


print(min(100, 200, 300, 400))

a)

100

b)

200

c)

300

d)

400

41.

What is the displayed value for Python coding below:


print(math.pi)

a)

3.141592653589793

b)

3.142

c)

31.41592653589793

d)

π

42.

What is the displayed value for Python coding below:


print(math.ceil(2.6))

a)

3

b)

2

c)

2.5

d)

3.5

43.

What is the displayed value for Python coding below:


print(math.floor(2.6))

a)

3

b)

2

c)

2.5

d)

3.5

44.

What is the displayed value for Python coding below:


print(max(-100, -200, +100, +200))

a)

+100

b)

+200

c)

100

d)

200

45.

multiplication of x and y

a)

x * y

b)

sqrt(x)

c)

exp(x)

d)

pow(x,y)

46.

factorial of the number X

a)

math.copysign(X, Y)

b)

math.factorial(X)

c)

math.fmod(X, Y)

d)

math.log(X, [base])

47.

the logarithm of X over the base base.

a)

math.cos(X)

b)

abs(x)

c)

math.log(X, [base])

d)

sqrt(x)

48.

If values of two operands are not equal, then condition becomes true.

a)

!=

b)

<

c)

>=

d)

<=

49.

the inverse cosine of X. In radians.

a)

math.cos(X)

b)

math.asin(X)

c)

math.acos(X)

d)

math.sin(X)

50.

The code snippet above outputs

a)

error

b)

None

c)

NaN

d)

-1

51.

The code above prints

a)

Math

Physics

Chemistry

English

b)

4

3.8

3.6

3.7

c)

None

None

None

None

d)

NaN

NaN

NaN

NaN

52.

The output of the code above is

a)

[101, 102, 103, 104]

b)

[3.6, 3.7, 3.8, 4]

53.

Which of the following are valid ways to create a dictionary like this

a)
b)
c)
d)
e)
54.

Which of the following code deletes the key 103 and its value

a)

del grades[103]

b)

grades.pop(103)

c)

del grades["103"]

d)

grades.pop("103")

e)
55.

pow(5,2) =



(a)  

56.

sqrt(64)

(a)  

57.

sqrt(100)

(a)  

58.

# in a print statement, you can only concatenate (+) string data !!!

votingAge = 18

print("you can vote when you are " + (a)   (votingAge))

59.

What type of data is this?

birthDate = "08.29.03"

a)

string

b)

floating point

c)

integer

d)

butter

60.

What is the extension of python library modules?

a)

.mod

b)

.lib

c)

.code

d)

.py

61.

In python which is the correct method to load a module math?

a)

include math

b)

import math

c)

#include<math.h>

d)

using math