Font size
WorksheetsPython Programming with modules
Total questions: 61
Worksheet time: 46mins
What is a library in python?
COLLECTION OF FILES
COLLECTION OF MODULES
IT IS SUBPROGRAM
NAME OF A FILE
exp(),floor()belongs which module?
cmath.py
urlib.py
math.py
statistics.py
Which operator is used in python to import all modules from package
-- operator
+ operator
* operator
----> operator
A variable defined inside the def() we called as
Global
enclosing
local
local to def()
What is the output of the following program :
y = 8
z = lambda x : x * y
print z(6)
48
22
8
24
This program will produce
a random number between 10 and 100 (including 10 but not 100) always in increments of 10
a random number between 10 and 100 (including 10 and 100) always in increments of 10
10 random numbers between 10 and 100 (including 10 and 100)
10 random numbers between 10 and 100 (including 10 and not 100)
This code is equivalent to
random.randint(1,11)
random.randint(1,10)
random.randrange(1,11,1)
random.randrange(1,10,1)
Which file must be part of the folder containing python module files to make it importable python package?
init.py
_setup_.py
_init_.py
setup.py
Which operator is used in python to import all modules from packages?
. operator
* operator
-> symbol
, operator
__________ is a library used to create data structures and carry out scientific calculations.
Python
Numpy
Pycharm
Bar chart
How to use numpy ?
import numpy as np
import pandas as pd
import pyplot as plt
Name the function used to create an array?
np.aray()
np.array()
Np.array()
np.arange()
np.arange(2,8,1) ----> what output will be produced?
2,3,4,5,6,7,8
2,3,4,5,6,7,8,9
2,3,4,5,6,7
2,4,6,8
np.array([4,7])
[ 4 7 ]
[ 4 5 6 7 ]
[ 4 5 6 ]
[ 1 2 3 4 5 6 7 ]
names = np.array(["Reem" , "Salah" , "Haya" , "Maryam" , "Fatema"])
print(names([2,3,4]))
Mark the right output from the below options
[ 'Haya' 'Maryam' 'Fatema' ]
[ 'Maryam' 'Haya' 'Fatema' ]
[ 'Reem' 'Salah' 'Fatema' ]
[ 'Reem' 'Salah' 'Haya' ]
names = np.array(["Reem" , "Salah" , "Haya" , "Maryam" , "Fatema"], dtype=object)
names[2] = "Omar"
print([names])
Mark the right output from the below options
['Reem', 'Salah', 'Omar', 'Maryam', 'Fatema']
[array(['Reem', 'Salah', 'Omar', 'Maryam', 'Fatema'], dtype=object)]
['Reem' 'Salah' 'Omar' 'Maryam' 'Fatema']
[['Reem' 'Salah' 'Omar' 'Maryam' 'Fatema']]
Each location of an element in an array is called ______________
Size
Length
Index
Element
Two dimensional arrays are also known as ______________
Subscripts
Matrices
ndarray
Vectors
One dimensional arrays are also known as _____________
Vectors
ndarray
Matrices
Subscript
_________________ returns the size of each element of array in bytes.
len()
itemsize
shape
type
A=np.array([1,2,3,4],dtype=np.float64)
What is the itemsize of array 'A'?
1
4
8
16
b=np.array([[1,2,3,4],[5,6,7,8],[10,11,12,13]])
Write the value of b[2,1].
3
6
10
11
x=np.array([9,4,2,7])
y=x+5
[14 9 7 12]
[14,9 ,7, 12]
[13 8 6 12]
[13,8 ,6 ,12]
_______________ function is used to change the dimension or shape of the array.(Select the code used for it.)
shape
reshape
reshape()
itemsize
What multiplication sentence does this array show?
4 X 8 = 32
4 X 8 = 31
5 X 8 = 32
4 X 8
What is a correct syntax to subtract the numbers from arr1 with the numbers from arr2?
np.substract(arr1, arr2)
np.min(arr1, arr2)
np.sub(arr1, arr2)
np.minus(arr1, arr2)
What is the correct method for getting the Natural Logarithm (Logarithm at base e)?
arr = np.arange(1, 10)
np.log(arr)
np.loge(arr)
np.natural(arr)
np.ln(arr)
When using the NumPy random module, how can you return a random number from 0 to 100?
random.randint(100)
random.rand()
random.rand(100)
When using the NumPy random module, how can you randomly shuffle an array?
arr = np.array([1, 2, 3, 4, 5])
random.change(arr)
random.shuffle(arr)
random.rearrange(arr)
When using the NumPy random module, how can you make sure you always get the same result?
Use the random.seed() function to set a seed before running the other random functions
Use the random.static() function to set an answer before running your random functions
Use the random.change() function to change an answer before running your random functions
What is a correct syntax to create a NumPy array?
np.createArray([1, 2, 3, 4, 5])
np.array([1, 2, 3, 4, 5])
np.object([1, 2, 3, 4, 5])
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])
print(arr[2:5])
print(arr[2:6])
print(arr[2:4])
print(arr[3:6])
What is a correct syntax to return the shape of an array?
shape(arr)
arr.shape
arr.shape()
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])
newarr = arr.reshape(3, 4)
newarr = arr.shape(3, 4)
newarr = arr.reshape(4, 3)
newarr = arr.shape(4, 3)
How to use numpy ?
import numpy as np
import pandas as pd
import pyplot as plt
NumPY stands for?
Numbering Python
Number In Python
Numerical Python
None Of the above
The most important object defined in NumPy is an N-dimensional array type called?
ndarray
narray
nd_array
darray
What is the displayed value for Python coding below:
print(min(100, 200, 300, 400))
100
200
300
400
What is the displayed value for Python coding below:
print(math.pi)
3.141592653589793
3.142
31.41592653589793
π
What is the displayed value for Python coding below:
print(math.ceil(2.6))
3
2
2.5
3.5
What is the displayed value for Python coding below:
print(math.floor(2.6))
3
2
2.5
3.5
What is the displayed value for Python coding below:
print(max(-100, -200, +100, +200))
+100
+200
100
200
multiplication of x and y
x * y
sqrt(x)
exp(x)
pow(x,y)
factorial of the number X
math.copysign(X, Y)
math.factorial(X)
math.fmod(X, Y)
math.log(X, [base])
the logarithm of X over the base base.
math.cos(X)
abs(x)
math.log(X, [base])
sqrt(x)
If values of two operands are not equal, then condition becomes true.
!=
<
>=
<=
the inverse cosine of X. In radians.
math.cos(X)
math.asin(X)
math.acos(X)
math.sin(X)
The code snippet above outputs
error
None
NaN
-1
The code above prints
Math
Physics
Chemistry
English
4
3.8
3.6
3.7
None
None
None
None
NaN
NaN
NaN
NaN
The output of the code above is
[101, 102, 103, 104]
[3.6, 3.7, 3.8, 4]
Which of the following are valid ways to create a dictionary like this
Which of the following code deletes the key 103 and its value
del grades[103]
grades.pop(103)
del grades["103"]
grades.pop("103")
pow(5,2) =
(a)
sqrt(64)
(a)
sqrt(100)
(a)
# in a print statement, you can only concatenate (+) string data !!!
votingAge = 18
print("you can vote when you are " + (a) (votingAge))
What type of data is this?
birthDate = "08.29.03"
string
floating point
integer
butter
What is the extension of python library modules?
.mod
.lib
.code
.py
In python which is the correct method to load a module math?
include math
import math
#include<math.h>
using math
