Font size
WorksheetsComputer Programming Python-2 Lab Quiz-1 CC
Total questions: 80
Worksheet time: 50mins
Best way to import the pandas module in your program ?
1.import pandas as p
2.import pandas as pd
3.import pandas as d
4.All of the above
DataFrame in pandas is
1. dimensional array
2. dimensional array
3.dimensional array
4.None of the above
All pandas data structures are ___ mutable but not always _______mutable.
a) size, value
b) semantic, size
c) value, size
d) none of the mentioned
Which is not a feature of series
Homogeneous data
Immutable size
Mutable data
Multiple rows
Pandas deals with following data structures
Series
Series and Data Frames
Series, DataFrames and Panel
None of Above
Which is true for series.
Size is mutable,Values is mutable
size is immutable,values is mutable
size is mutable,values is immutable.
none
Series.tail(3) will return how many values.
3 values from front
3 values from last
5 values
none
Series.head() will return how many rows.
2
3
4
5
we can analyze the data in pandas with :
Series
Dataframe
Both
none
Series in Pandas is
1 Dimensional Array
2 Dimensional array
3 Dimensional array
none of above
In data science, which of the python library is more popular ?
numpy
pandas
django
none
Which is not a feature of series
Homogeneous data
Immutable size
Mutable data
Multiple rows
Full form of NaN is
Not a Null
Not a Number
Not a Numeric
None of these
pandas is a:
Data Structure
Series
Dataframe
Library
Write the output for the following:
import pandas as pd1
s = pd1.Series(5, index=[0, 1, 2, 3])
print(s)
0 5
0 5
1 5
2 5
3 5
dtype: int64
1 5
2 5
2 5
4 5
dtype: int64
0 5
1 5
2 5
3 5
dtype: object
write the output:
import pandas as pd1
s = pd1.Series([1,2,3])
t = pd1.Series([1,2,4])
u=s-t
print (u)
0 1
1 0
2 1
dtype: int64
0 0
1 0
2 1
dtype: int64
0 0
1 0
2 -1
dtype: float64
0 0
1 0
2 -1
dtype: int64
write the output:
import pandas as pd
s=pd.Series([1,2,3,4],index=['a','b','c','d'])
print(s.loc['b':'d'])
b 2
c 3
d 4
dtype: float64
b 2
c 3
d 4
dtype: object
c 3
d 4
dtype: int64
b 2
c 3
d 4
dtype: int64
To extract subset from Series,the following function is used
row()
column()
loc()
all
Which of the following statement/s will give 2 rows from bottom of the dataframe ?
Print(df.tail())
print(df.tail(2))
print(df.tail[2])
print(df.tail(4))
The instructor wants to add a new column, Marks to the dataframe. The values of the marks will be 12, 22, 21, 24. Help him to choose the correct command to do so.
a) Df.columns=[12, 22, 21, 24]
b) df[‘marks’] = [12, 22, 21, 24]
c) df.loc[marks] = [12, 22, 21, 24]
d) Both (b) and (c) are correct
___________ attribute is used to specify column labels
column ()
column
columns()
columns
To get number of elements in a DataFrame _____ attribute may be used.
size
shape
values
ndim
To extract a row / column from a DataFrame ___ function may be used
row()
column()
loc()
All of the above
Best way to import the pandas module in your program ?
1.add pandas
2.import pandas as pd
3.Pandas import as pd
4.All of the above
DataFrame in pandas is
1 dimensional array
2 dimensional array
3 dimensional array
4.None of the above
You can use numpy _______________ for missing data.
NaN
notanumber
none
0
Which command used to change the screen size?
window = Tk()
window.mainloop()
window.geometry("400x300")
Which of the following is easy to use from the user?
Command Line
GUI (Graphical User Interface)
__________ is an element of GUI.
Widget
GUI
Application
Which is the correct way to use tkinter in python
program?
include tkinter *
import tkinter *
from tkinter import *
from tkinter include *
Which of the following function used to create window in
python tkinter.
window()
tk()
toolkit()
wd()
Which of the following attribute used to change the text
color of a Label widget in python tkinter
fg
foreground
bg
background
Which of the following attribute used to change the
background color of a Label widget in python tkinter
background
bg
fg
foreground
What is the full form of GUI?
Graphic Unit Interface
Graphical User Interface
Graphic Unit Input
______________ library provides fast and easy way to create GUI applications in Python.
Tkinter
IbtikarMaker
Graph
Choose the correct statement to display title.
window.title("My First Program")
window.title(My First Program)
window.title "My First Program"
Label , Button , Sliders are all examples of Widgets.
True
False
Which function is used to set the size of the tkinter
window?
setsize()
size()
geometry()
dimension()
What is the use of mainloop() function in tkinter window?
To create the window screen
To hold the window screen
To delete the window screen
To disable the window screen
What is tkinter?
A Python GUI module
A Python Scripting module
It provides a scrollbar to the use so that the use can scroll the window up and down.
Scrollbar()
Spinbox()
Menu()
Entry()
What does inheritance mean in python?
The transfer of the characteristics of a class to other classes that are derived from it.
A variable that is defined inside a method and belongs only to the current instance of a class
The creation of an instance of a class.
It is what you sometimes get when a relative passes away
What is an instance in python?
A special kind of function that is defined in a class definition.
The creation of an instance of a class.
An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
A moment in time
What is an object in python?
A unique instance of a of a class. An object comprises both data members (class variables and instance variables) and methods.
A special kind of function that is defined in a class definition.
The assignment of more than one function to a particular operator.
An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.
What is a Python class?
A function to create an object.
A template (blueprint) for creating objects.
A procedure related to an object.
A process that repeats are directed.
Identify the code that properly creates an instance of a class named Car.
camero.car(make, model)
tesla = car.make()
mustang = Car(make,model)
porsche = car.make.model()
What does __init__ do?
Constructs the instance
Initialize the instance values
Calls the Super class
Creates a circle
Getters and setters
Are important for class incapsulation
Are important to add each data member of the class
Are replaced by the @property decorator in Python
Are replaced by the @classmethod in Python
Class Healthcare has the methods Pharmacy() and Labs(). Class Hospitals is derived from Healthcare and has the methods Doctor(), Patients(), and Nurses(). Afterh = Hospitals()executes, how many different methods can object h call, ignoring constructors?
7
5
3
4
A derived class may define a method having the same name as the base class means that:
a derived class method overrides the method of the base class
a base class method overrides the method of the derived class.
the functionality of the method is the same in both derived and base class.
a derived class method overloads the method of the base class.
Which is an example of inheritance?
class Library:
def __init__(self):
self.name = ''
class Books:
def __init__(self):
self.number = ''
class Pages:
def __init__(self):
self.number = ''
self.words = ''
self.paragraphs = ''
class Car:
def __init__(self):
self.type = ''
class Boat:
def __init__(self):
self.model = ''
class Engine:
def __init__(self):
self.model = ''
self.type = ''
self.power =''
class Garden:
def __init__(self):
self.name = ''
class Trees:
def __init__(self):
self.name = ''
self.type = ''
self.number = ''
class Elements:
def __init__(self):
self.name = ''
class Metal(Elements):
def __init__(self):
Elements.__init__(self)
self.mass = ''
self.atomicNumber = ''
class NonMetal(Elements):
def __init__(self):
Elements.__init__(self)
self.mass = ''
self.atomicNumber = ''
In the following code, I want to throw an exception if the denominator is not negative. What should I put after starting my function>
def div(n,d):
if d == negative:
try ('No negatives, moron')
if d == negative:
raise ('No negatives, moron')
if d<0:
raise Exception('I said no negative numbers, dimwit')
if d<0:
try Exception('I said no negative numbers, dimwit')
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
The equivalent of the above for loop using the while syntax would be
The above program prints
Numbers 1 to 10 in reverse order
Numbers 1 to 11 in reverse order
Numbers 1 to 10
Numbers 1 to 11
The code above prints all numbers between 1 and 30 that are
not divisible by 5
divisible by 5
The program above prints the sum of
all odd numbers less than 100
all even numbers less than 100
all numbers less than 100
The program above prints the sum of all the numbers between 0 and 101 that are
alternate odd numbers
alternate even numbers
alternate numbers
What is the output of the program above
10
15
18
17
16
What is the output of the following code
dict1 = {"key1":1, "key2":2}
dict2 = {"key2":2, "key1":1}
print(dict1 == dict2)
True
False
Select correct ways to create an empty dictionary
sampleDict = {}
sampleDict = dict()
sampleDict = dict{}
Please select all correct ways to empty the following dictionary
student = {
"name": "Emma",
"class": 9,
"marks": 75
}
del student
del student[0:2]
student.clear()
Dictionary keys must be immutable
True
False
In Python, Dictionaries are immutable
True
False
________________method removes all items from the particular dictionary.
clear( )
pop( )
del ( )
_________________ method will not only delete the item from dictionary, but also return the deleted value.
del ( )
pop( )
Clear( )
_______________this method deletes the item from the dictionary
pop( )
del( )
clear( )
________________method will returns number of key-value pairs in the given dictionary.
len( )
pop( )
del( )
keys( )
values( )
What is the output of the following list assignment
aList = [4, 8, 12, 16]
aList[1:4] = [20, 24, 28]
print(aList)
[4, 20, 24, 28, 8, 12, 16]
[4, 20, 24, 28]
What is the output of the following list operation
aList = [10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
print(aList[:4])
print(aList[3:])
[20, 30, 40, 50]
[10, 20, 30, 40]
[30, 40, 50, 60, 70, 80]
[30, 40, 50]
[10, 20, 30, 40]
[40, 50, 60, 70, 80]
None of these
Select all the correct options to join two lists in Python
listOne = ['a', 'b', 'c', 'd']
listTwo = ['e', 'f', 'g']
newList = listOne + listTwo
newList = extend(listOne, listTwo)
newList = listOne.extend(listTwo)
newList.extend(listOne, listTwo)
What is the output of the following
aList = [5, 10, 15, 25]
print(aList[::-2])
[15, 10, 5]
[10, 5]
[25, 10]
What is the output of the following list function?
sampleList = [10, 20, 30, 40, 50]
sampleList.append(60)
print(sampleList)
sampleList.append(60)
print(sampleList)
[10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60, 60]
[10, 20, 30, 40, 50, 60]
[10, 20, 30, 40, 50, 60]
both are wrong
In Python, list is mutable
False
True
What will be the output of below Python code?
list1=[8,0,9,5]
print(list1[::-1])
[5,9,0,8]
[8,0,9]
[8,0,9,5]
[0,9,5]
Which of the following will give output as [23,2,9,75] ?
If list1=[6,23,3,2,0,9,8,75]
print(list1[1:7:2])
print(list1[0:7:2])
print(list1[1:8:2])
print(list1[0:8:2])
Suppose list1 is [1, 3, 2], What is list1 * 2 ?
[2, 6, 4].
[1, 3, 2, 1, 3]
[1, 3, 2, 1, 3, 2]
[1, 3, 2, 3, 2, 1]
a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']
Which display correct output from below ?
print(a[-5:-3])
['bar', 'baz']
print(a[4::-1])
['quux', 'baz', 'foo']
None
print(a[2])
['bar']
____________function can be used to insert an element/object at a specified index.
extend( )
insert ( )
append( )
