wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Computer Programming Python-2 Lab Quiz-1 CC

Total questions: 80

Worksheet time: 50mins

Name
Class
Date
1.

Best way to import the pandas module in your program ?

a)

1.import pandas as p

b)

2.import pandas as pd

c)

3.import pandas as d

d)

4.All of the above

2.

DataFrame in pandas is

a)

1. dimensional array

b)

2. dimensional array

c)

3.dimensional array

d)

4.None of the above

3.

All pandas data structures are ___ mutable but not always _______mutable.

a)

a) size, value

b)

b) semantic, size

c)

c) value, size

d)

d) none of the mentioned

4.

Which is not a feature of series

a)

Homogeneous data

b)

Immutable size

c)

Mutable data

d)

Multiple rows

5.

Pandas deals with following data structures

a)

Series

b)

Series and Data Frames

c)

Series, DataFrames and Panel

d)

None of Above

6.

Which is true for series.

a)

Size is mutable,Values is mutable

b)

size is immutable,values is mutable

c)

size is mutable,values is immutable.

d)

none

7.

Series.tail(3) will return how many values.

a)

3 values from front

b)

3 values from last

c)

5 values

d)

none

8.

Series.head() will return how many rows.

a)

2

b)

3

c)

4

d)

5

9.

we can analyze the data in pandas with :

a)

Series

b)

Dataframe

c)

Both

d)

none

10.

Series in Pandas is

a)

1 Dimensional Array

b)

2 Dimensional array

c)

3 Dimensional array

d)

none of above

11.

In data science, which of the python library is more popular ?

a)

numpy

b)

pandas

c)

django

d)

none

12.

Which is not a feature of series

a)

Homogeneous data

b)

Immutable size

c)

Mutable data

d)

Multiple rows

13.

Full form of NaN is

a)

Not a Null

b)

Not a Number

c)

Not a Numeric

d)

None of these

14.

pandas is a:

a)

Data Structure

b)

Series

c)

Dataframe

d)

Library

15.

Write the output for the following:

import pandas as pd1

s = pd1.Series(5, index=[0, 1, 2, 3])

print(s)

a)

0 5

b)

0 5

1 5

2 5

3 5

dtype: int64

c)

1 5

2 5

2 5

4 5

dtype: int64

d)

0 5

1 5

2 5

3 5

dtype: object

16.

write the output:

import pandas as pd1

s = pd1.Series([1,2,3])

t = pd1.Series([1,2,4])

u=s-t

print (u)

a)

0 1

1 0

2 1

dtype: int64

b)

0 0

1 0

2 1

dtype: int64

c)

0 0

1 0

2 -1

dtype: float64

d)

0 0

1 0

2 -1

dtype: int64

17.

write the output:

import pandas as pd

s=pd.Series([1,2,3,4],index=['a','b','c','d'])

print(s.loc['b':'d'])

a)

b 2

c 3

d 4

dtype: float64

b)

b 2

c 3

d 4

dtype: object

c)

c 3

d 4

dtype: int64

d)

b 2

c 3

d 4

dtype: int64

18.

To extract subset from Series,the following function is used

a)

row()

b)

column()

c)

loc()

d)

all

19.

Which of the following statement/s will give 2 rows from bottom of the dataframe ?

a)

Print(df.tail())

b)

print(df.tail(2))

c)

print(df.tail[2])

d)

print(df.tail(4))

20.

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)

a) Df.columns=[12, 22, 21, 24]

b)

b) df[‘marks’] = [12, 22, 21, 24]

c)

c) df.loc[marks] = [12, 22, 21, 24]

d)

d) Both (b) and (c) are correct

21.
A Dataframe contains Heterogeneous data
a)
true
b)
false
22.

___________ attribute is used to specify column labels

a)

column ()

b)

column

c)

columns()

d)

columns

23.

To get number of elements in a DataFrame _____ attribute may be used.

a)

size

b)

shape

c)

values

d)

ndim

24.

To extract a row / column from a DataFrame ___ function may be used

a)

row()

b)

column()

c)

loc()

d)

All of the above

25.

Best way to import the pandas module in your program ?

a)

1.add pandas

b)

2.import pandas as pd

c)

3.Pandas import as pd

d)

4.All of the above

26.

DataFrame in pandas is

a)

1 dimensional array

b)

2 dimensional array

c)

3 dimensional array

d)

4.None of the above

27.

You can use numpy _______________ for missing data.

a)

NaN

b)

notanumber

c)

none

d)

0

28.

Which command used to change the screen size?

a)

window = Tk()

b)

window.mainloop()

c)

window.geometry("400x300")

29.

Which of the following is easy to use from the user?

a)

Command Line

b)

GUI (Graphical User Interface)

30.

__________ is an element of GUI.

a)

Widget

b)

GUI

c)

Application

31.

Which is the correct way to use tkinter in python

program?

a)

include tkinter *

b)

import tkinter *

c)

from tkinter import *

d)

from tkinter include *

32.

Which of the following function used to create window in

python tkinter.

a)

window()

b)

tk()

c)

toolkit()

d)

wd()

33.

Which of the following attribute used to change the text

color of a Label widget in python tkinter

a)

fg

b)

foreground

c)

bg

d)

background

34.

Which of the following attribute used to change the

background color of a Label widget in python tkinter

a)

background

b)

bg

c)

fg

d)

foreground

35.

What is the full form of GUI?

a)

Graphic Unit Interface

b)

Graphical User Interface

c)

Graphic Unit Input

36.

______________ library provides fast and easy way to create GUI applications in Python.

a)

Tkinter

b)

IbtikarMaker

c)

Graph

37.

Choose the correct statement to display title.

a)

window.title("My First Program")

b)

window.title(My First Program)

c)

window.title "My First Program"

38.

Label , Button , Sliders are all examples of Widgets.

a)

True

b)

False

39.

Which function is used to set the size of the tkinter

window?

a)

setsize()

b)

size()

c)

geometry()

d)

dimension()

40.

What is the use of mainloop() function in tkinter window?

a)

To create the window screen

b)

To hold the window screen

c)

To delete the window screen

d)

To disable the window screen

41.

What is tkinter?

a)

A Python GUI module

b)

A Python Scripting module

42.

It provides a scrollbar to the use so that the use can scroll the window up and down.

a)

Scrollbar()

b)

Spinbox()

c)

Menu()

d)

Entry()

43.

What does inheritance mean in python?

a)

The transfer of the characteristics of a class to other classes that are derived from it.

b)

A variable that is defined inside a method and belongs only to the current instance of a class

c)

The creation of an instance of a class.

d)

It is what you sometimes get when a relative passes away

44.

What is an instance in python?

a)

A special kind of function that is defined in a class definition.

b)

The creation of an instance of a class.

c)

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.

d)

A moment in time

45.

What is an object in python?

a)

A unique instance of a of a class. An object comprises both data members (class variables and instance variables) and methods.

b)

A special kind of function that is defined in a class definition.

c)

The assignment of more than one function to a particular operator.

d)

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.

46.

What is a Python class?

a)

A function to create an object.

b)

A template (blueprint) for creating objects.

c)

A procedure related to an object.

d)

A process that repeats are directed.

47.

Identify the code that properly creates an instance of a class named Car.

a)

camero.car(make, model)

b)

tesla = car.make()

c)

mustang = Car(make,model)

d)

porsche = car.make.model()

48.

What does __init__ do?

a)

Constructs the instance

b)

Initialize the instance values

c)

Calls the Super class

d)

Creates a circle

49.

Getters and setters

a)

Are important for class incapsulation

b)

Are important to add each data member of the class

c)

Are replaced by the @property decorator in Python

d)

Are replaced by the @classmethod in Python

50.

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?

a)

7

b)

5

c)

3

d)

4

51.

A derived class may define a method having the same name as the base class means that:

a)

a derived class method overrides the method of the base class

b)

a base class method overrides the method of the derived class.

c)

the functionality of the method is the same in both derived and base class.

d)

a derived class method overloads the method of the base class.

52.

Which is an example of inheritance?

a)

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 = ''

b)

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 =''

c)

class Garden:

def __init__(self):

self.name = ''

class Trees:

def __init__(self):

self.name = ''

self.type = ''

self.number = ''

d)

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 = ''

53.

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):

a)

if d == negative:

try ('No negatives, moron')

b)

if d == negative:

raise ('No negatives, moron')

c)

if d<0:

raise Exception('I said no negative numbers, dimwit')

d)

if d<0:

try Exception('I said no negative numbers, dimwit')

54.

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

55.

The equivalent of the above for loop using the while syntax would be

a)
b)
c)
d)
56.

The above program prints

a)

Numbers 1 to 10 in reverse order

b)

Numbers 1 to 11 in reverse order

c)

Numbers 1 to 10

d)

Numbers 1 to 11

57.

The code above prints all numbers between 1 and 30 that are

a)

not divisible by 5

b)

divisible by 5

58.

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

59.

The program above prints the sum of all the numbers between 0 and 101 that are

a)

alternate odd numbers

b)

alternate even numbers

c)

alternate numbers

60.

What is the output of the program above

a)

10

b)

15

c)

18

d)

17

e)

16

61.

What is the output of the following code

dict1 = {"key1":1, "key2":2}

dict2 = {"key2":2, "key1":1}

print(dict1 == dict2)

a)

True

b)

False

62.

Select correct ways to create an empty dictionary

a)

sampleDict = {}

b)

sampleDict = dict()

c)

sampleDict = dict{}

63.

Please select all correct ways to empty the following dictionary

student = {

"name": "Emma",

"class": 9,

"marks": 75

}

a)

del student

b)

del student[0:2]

c)

student.clear()

64.

Dictionary keys must be immutable

a)

True

b)

False

65.

In Python, Dictionaries are immutable

a)

True

b)

False

66.

________________method removes all items from the particular dictionary.

a)

clear( )

b)

pop( )

c)

del ( )

67.

_________________ method will not only delete the item from dictionary, but also return the deleted value.

a)

del ( )

b)

pop( )

c)

Clear( )

68.

_______________this method deletes the item from the dictionary

a)

pop( )

b)

del( )

c)

clear( )

69.

________________method will returns number of key-value pairs in the given dictionary.

a)

len( )

b)

pop( )

c)

del( )

d)

keys( )

e)

values( )

70.

What is the output of the following list assignment

aList = [4, 8, 12, 16]

aList[1:4] = [20, 24, 28]

print(aList)

a)

[4, 20, 24, 28, 8, 12, 16]

b)

[4, 20, 24, 28]

71.

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:])

a)

[20, 30, 40, 50]

[10, 20, 30, 40]

[30, 40, 50, 60, 70, 80]

b)

[30, 40, 50]

[10, 20, 30, 40]

[40, 50, 60, 70, 80]

c)

None of these

72.

Select all the correct options to join two lists in Python

listOne = ['a', 'b', 'c', 'd']

listTwo = ['e', 'f', 'g']

a)

newList = listOne + listTwo

b)

newList = extend(listOne, listTwo)

c)

newList = listOne.extend(listTwo)

d)

newList.extend(listOne, listTwo)

73.

What is the output of the following

aList = [5, 10, 15, 25]

print(aList[::-2])

a)

[15, 10, 5]

b)

[10, 5]

c)

[25, 10]

74.

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)

a)

[10, 20, 30, 40, 50, 60]

[10, 20, 30, 40, 50, 60, 60]

b)

[10, 20, 30, 40, 50, 60]

[10, 20, 30, 40, 50, 60]

c)

both are wrong

75.

In Python, list is mutable

a)

False

b)

True

76.

What will be the output of below Python code?

list1=[8,0,9,5]


print(list1[::-1])

a)

[5,9,0,8]

b)

[8,0,9]

c)

[8,0,9,5]

d)

[0,9,5]

77.

Which of the following will give output as [23,2,9,75] ?

If list1=[6,23,3,2,0,9,8,75]

a)

print(list1[1:7:2])

b)

print(list1[0:7:2])

c)

print(list1[1:8:2])

d)

print(list1[0:8:2])

78.

Suppose list1 is [1, 3, 2], What is list1 * 2 ?

a)

[2, 6, 4].

b)

[1, 3, 2, 1, 3]

c)

[1, 3, 2, 1, 3, 2]

d)

[1, 3, 2, 3, 2, 1]

79.

a = ['foo', 'bar', 'baz', 'qux', 'quux', 'corge']

Which display correct output from below ?

a)

print(a[-5:-3])

['bar', 'baz']

b)

print(a[4::-1])

['quux', 'baz', 'foo']

c)

None

d)

print(a[2])

['bar']

80.

____________function can be used to insert an element/object at a specified index.

a)

extend( )

b)

insert ( )

c)

append( )