0% found this document useful (0 votes)
41 views28 pages

INT213 Answer Key

The document contains 21 multiple choice questions related to Python programming. The questions cover topics like functions, lists, conditionals, loops, classes, files, exceptions and Tkinter GUI programming. For each question, answer options are given and the correct answer is highlighted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views28 pages

INT213 Answer Key

The document contains 21 multiple choice questions related to Python programming. The questions cover topics like functions, lists, conditionals, loops, classes, files, exceptions and Tkinter GUI programming. For each question, answer options are given and the correct answer is highlighted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

2015 A

EB1E TQ1:What will be the output of the following python iš


BHcode?

a-2

def fun(a=3):

global a

at=5

fun)

print(a)

hi
at
Ans-: Error
vH
ra
au
/S

Q2-: consider the following statement and choose the correct option:
/c
m

a=[10,4, 1, 50, 8, 2]
co
e.

b=sorted(a, reverse='No)
ub
ut

print(b)
yo

(1,2,4,8,10,50)

(50, 10, 8, 4, 2, 1)

[10, 4, 1, 50, 8, 2)

Error

Ans=: Error

Q3-: What will be the output of the following statements?

s1="Hello World"
s2=is1-3:-7-1]

print(s)

Ans-: roW

Q4-: What will be the output of the following code:

If (3-4//2):

print("Hello")

else:

hi
at
print("Hii") vH
ra
au

Ans-: Hello
/S
/c
m

Q5-: Consider the following statements and choose the


co
e.

correct option:
ub
ut

a=(10, 20, 30, 40)


yo

a.insert(50, 3)

Ans-: Error because insert operator not supported

Q6-
COunUFU
tor 1 1n range (i0)

Countt=i

if i==3:

break

Orint (COunt)
Ans-: 6

Q7-: consider the following statements and choose the correct option:

a=[10, 20, 30, 40]

a.insert(10, 3)

Ans-:3 will be inserted at the last position.

Q8:Which of the following is having highest precedence?

hi
*

at
vH
ra
au
/S
/c
m
co
e.
ub

Ans-: 0
ut
yo

Q9: Consider the following statement and choose the correct

option:

s1="Hello World"

S2=S1

s1 is the alias of s2.

ld of s1 and s2 is same.

ld of s1 and s2 is different.
None of these

Ans-: Id of s1 and s2 is same

Q10-: Which of the following syntax is used to make a data

member protected in a class.

protected

hi
ind

at
variable name
vH
ra
au

Ans-
/S
/c
m

Q11:Which of the following statements come in this python code?


co
e.

class Name:
ub

def init_(self,x):
ut
yo

Self.x=x

name1=Name("ABC")

name2name1

It will throw the error as multiple references to the same object is not possible

id(name1) and id(name2) will have same value.

Both name1 and name2 will have reference to two different objects of class Name

All of the above

Ans-: id(name1) and id(name2) will have same value


Q12: What will be the output of the following code?

Count 0

For i in range(10):

Count+=i

If i==3:

Break

Print(count)

hi
at
6
vH
ra
au

3
/S
/c
m

37
co
e.
ub

34
ut
yo

Ans-:6

Q13-

What will be the output of the following code?

Class Name:

Count = 0

def Lnit (self, x):

self.x
Name.count t I

namel = Name (" ABC")


name 2 namel

rint(namel.

Ans-: {'x': 'ABC'}

Q14-: class student:

definit(self):

self.name="abc"

self.roll=1

hi
def init_(self, name, roll):

at
selt.name=name vH
ra
self.roll =roll
au
/S

obj1=student)
/c
m

What will be the output of above code?


co
e.
ub

Ans-:lt gives error because second constructor ovenwrites the first constructor.so we need to
ut

pass 2 arguments.
yo

Q15-: Which access specifier is by default in class data member and member function

Ans-: public

Q16-: What will be the output of the following code?

a = 4//2

b 4//0

C 4//4
printa)

print(b)

print(c)

Ans-: Zero division error

Q17-
open ("mytile.txt"rW")
f. write ("Python Programming")

hi
f.write ("Python Programming ")

at
f.close ()
vH
f=open ("myfile txt ", "r")
ra
.
au

orint (f.read ())


/S
/c

Ans-: Python Programming Python Programming


m
co
e.

Q18-: Consider a file "MyFile. txt" saved in the local/working directory, which of the following
ub

commands can be used to open it in the writing mode?


ut

Ans-:f open("MyFile. txt", "w")


yo

Q19-: What will be the output of the following code?

import pickle

f open("myfile.txt", "w")

pickle. dump("Python", f)

pickle. dump("Programming", f
f.close0

f open("myfile. txt", "r")

print(pickle.load(f))

Ans-: none of the above

Q20-: What will be the output of the following code?

a 4//2

hi
=

at
try:
vH
b =4//0
ra
au

xcept
/S

print ("Exception")
/c

c=4//4
m
co

print(a)
e.

print (b))
ub
ut

print (c)
yo

Ans-: Exception

Name Error

Q21: Choose the correct statement for the following code.

from tkinter import

top Tk)0
top.geometry("250x250")

label= Label(top, text = "Welcome")

label.pack0

top.mainloop)
Ans : It will create a label with "Welcome" labelled on it and pack it on the window

Q22- from tkinter import*

top = Tk ()

top.geometry ("250x250")
bl=Button (top, text="Button 1")
bl.grid ()

hi
b2=Button (top, text="Button 2")

at
b2 .grid ()

top. mainloop (0
vH
ra
au

Ans-: After the execution ,b1 will be placed above b2 on the top window
/S
/c
m

023-from tkinterimport
co
e.

Erom t kinter import*


ub

root Tk ()
ut

root . geometry ("250x250 ")


yo

FIntVar ()

=
R1 Radiobutton (root, text="A", variable=v, value=1)

RI. pack ()

R2 =
Radi obutton (root, text="B", variable=v, value=2)

R2. pack ()

R3 =
Radi obutton (root, text="C" , variable=v, value=3)
R3 . pack ()

root .mainloop ()

Which method can be used to obtain the value associated with the selected Radiobutton?

Ans=: v.get)
Q24-: What will be the output of the following code?

f open'myfile.txt", w)

f.write("Indian")

f.write("n")

f.write("Premier")

hi
f.write("\n")

at
f.write("League") vH
ra
au

f.close)
/S

f
/c

open("'myfile.txt",r)
m
co

print(f.read0)
e.
ub

f.close0
ut
yo

Ans-: None of the above

Q25-: In the GUI programming, origin of the coordinate system is specified by the

Ans-: Top-Left corner of the window/frame

Q26: Choose the correct statement for the following code

from tkinter import*

top = TkO

top.geometry("250x250")
button Button(top, text= "OK")

button.pack()

top.mainloop)

Ans-: It will create a button with "OK" labelled on it and pack it on the window specified by
top

Q27-: Consider the following code and choose the correct statement .

open ("filel.txt", " W")

f. write ("Python Programming" )

Close ()

hi
at
vH
Ans-: It will create a new file "file1.txt" in the working directory and write Python
ra
Programming" in it
au
/S
/c

Q28-: What will be the output of the following code?


m
co

import pickle
e.
ub

f open("myfile. txt", "wb")


ut
yo

pickle. dump(123.45, f)

f.close)

f open("myfile.txt", "rb")

print(pickle.load(f))

Ans-: 123.45

Q29-: What will be the output of the following code

=open (
"myfile8. txt'", "w")

f. write ("Pythan Programming")


f. write (" \n'")
f. write ("Python Programming ")
f.close ()

open ("myfile8 . txt", "r")

print (f. read ())

I .Close ()

Ans-: Pythan Programming

Python Programming

30. Assuming the credentials to be correct and the table students exists, choose the correct
statement for the following code

hi
at
import mysql.connector vH
ra
mydb = mysql.connector.connect
au

host "localhost"
/S

user="root"
/c
m

password="12345"
co

database= "mydatabase"
e.
ub
ut

my_cursor = mydb.cursor()
yo

query = "INSERT INTO students(Name, RollNo, Course) VALUES(%s, %s, %s) "

values [("ABC",121, "B Tech ")]

my_cursor.executemany(query, values)

mydb.commit()

OPTIONS:

It will insert ABC, 121, and B.Tech to the columns Name, RolINo, and Course respectively in the
students table

It will give error as SQL command is not valid


It gives error as there is a mismatch in the datatypes

None of the above

31. Consider the following code and choose the correct statement. Assume the credentials to be
correct.

import mysql.connector

mydb mysql.connector.comnect(

hi
=

at
host "localhost",
user = "root",
vH
ra
au

passwd = "12345",
/S

=
database "myDB"
/c
m
co

my_cursor = mydb.cursor()
e.

query = "SELECT * FROM students"


ub

my cursor.execute(query)
ut
yo

for rec in my_cursor:

print(rec)

OPTIONS :

It will print all the rows of table students in the ascending order.
It will print all the rows of table students in the descending order.
It will print all the rows of table students in the order of their insertion.
It will give error as print() is not supported in mysql
32. Consider the following code and choose the correct statement. Assume the credentials to be
correct.

import mysql.connector

mydb mysql.comnector.comnect(

hi
=

at
host = "localhost",
vH
ra
au
/S

user = "root",
/c
m
co

passwd = "12345",
e.
ub

database = "myDB"
ut
yo

my_cursor = mydb.cursor()

query =
"SELECT* FROM students ORDER BY Name DESC"

my_cursor.execute(query)

for rec in my_cursor:


print(rec)

OPTIONS

It will print all the rows of table students in the ascending order of the Name attribute.

It will print all the rows of table students in the descending order of the Name attribute.

hi
at
vH
ra
It will print all the rows of table students in the order of their insertion.
au
/S
/c
m

It will give error as print() is not supported in mysq|.


co
e.
ub
ut

33. What SQL command will be used if you want to delete an existing table named as students?
yo

OPTIONS:

DELETE TABLE students

DELETE * FROM students

DROP TABLE students

DROP students
34. Which of the following is the correct statement for numpy?

numpy stands for Numerical Python.

numpy stands for Numbered Python.

numpy stands for Numerous Python.

hi
numpy is not an abbreviation

at
vH
ra
35. Consider the following code and choose the correct statement. Assume the credentials to be
au

correct.
/S
/c

import mysql. connector


m
co
e.

mydb = mysql. connector. connect(


ub
ut
yo

host "localhost",

user = "root",

passwd= "abc@123"

my_cursor = mydb. cursor()

my_cursor. execute("SHOW DATABASES")


for db in my_cursor

print(db)

OPTIONS

It will show the names of all databases which have been created.
It will show the names of all databases which have been created along with their time of creation.
It will give error as SQL command is invalid.

None of the above

hi
at
36. The SQL command to create a database "mydatabase" is vH
ra
CREATE DATABASE mydatabase
au
/S
/c
m

37. What will happen after execution of following sql command:


co

UPDATE students SET rollno = 25 WHERE name= 'sachin'


e.
ub

OPTION:
ut

It will set the rollno attribute equal to 25 in all the rows where name is Sachin
yo

38. Output:

import mysql.connector

mydb = mysql.connector.connect(

host "localhost",

user = "root",

passwd "abc@123"

database = "mydatabase"

my cursor = mydb.cursor()
query CREATE TABLE students (name varchar(40), rollno int(10), course varchar(20))
my cursor.execute(query)

mydb.commit()

It will give error

39. Consider the following code and choose the correct statement. Assume the credentials to b

import mysql.connector

hi
mydb= mysql.connector.comnect(

at
vH
ra
host = "localhost",
au
/S

user = "root",
/c
m
co

passwd = "12345",
e.
ub
ut

database = "myDB"
yo

my_cursor = mydb.cursor()

query= "SELECT* FROM students ORDER BY Name" my_cursor.execute(query)

for rec in my_cursor:

print(rec)
It will print all the rows of table students in the ascending order of the Name attribute.

it will print all the rows of table students in the descending order of the Name attribute

It will print all the rows of table students in the order of their insertion

it will give error as print() is not supported in mysql

40. Which clause/statement in SQL is used to fetch the rows from a table based on certain
conditions
Both where and If can be used

hi
at
vH
ra
au

41. What will be the output of following code?


/S

Import pandas as pd
/c

Data ("car":{"s-cross", "innova","Santro"'],


m
co

"manufacturer":["Suzuki","toyota","Hyundai"l,
e.

"mileage":[24,18,22]
ub
ut
yo

D pd.DataFrame(data,index = ["car1","car2","car3"])
Print(type(D))

class 'pandas.core.frame.Data Frame'>

42. Choose the correct statement

Choose the correct statement.

matplotlib is used to perform advanced mathematical operations in Python

matplotlib is used to plot graphs in Python.


matplotlib is used to deal with multidimensional data structures in Python.

matplotlib is used to deal with multidimensional arrays in Python.

43. Consider the following code:

import pandas as pd

data = [["Corolla", "Toyota"].["Baleno", "Suzuki"],["Creta","Hyundai"]]

hi
at
print (df) vH
ra
au

Which statement should be written in the blank space to get the following output?
/S
/c
m

Name Brand
co
e.
ub

O Corolla Toyota
ut
yo

1. Baleno Suzuki

2 Creta Hyundai

df-data DataFrame(columns-["Name" "Brand"))

df-pd.data.Data Frame(columns-("Name","Brand"])

df =pd.DataFrame(data,columns="Name", "Brand"])

df pd DataFrame(data, columns-[Name,Brand)
44. Consider the following code:

from matplotlib import pyplot as plt

x= (1, 2, 3, 4, 5)

y=(2, 5, 10, 17, 26)

plt. xlabel("x axis")

hi
at
plt. ylabel("y axis") vH
ra
au

plt.plot(x, y)
/S
/c
m

plt.show()
co
e.
ub

The graph plotted after execution will satisfy the equation


ut
yo

y-2x+1

Y 3x+1

y=x^2+1

y 2x^2
45. What will be the output of the following code?

import numpy as np

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

print(a. shape)

(3, 2)

hi
3, 21

at
vH
ra
(2,3)
au
/S

[2,3]
/c
m
co
e.
ub
ut
yo

46. The graph plotted after execution of the following code will correspond to

from matplottib import pyplotas pli

x= np arange(0,3* np.pl, 0.1)

y np.sin(x)

pit.plot(x,y)

pit show()
the following code will correspond to

Sin wave

Straight line

Ellipse

None of the above

hi
47. Choose the correct output of the following code:

at
Import pandas as pd vH
ra
D= {a":1,"b":2,"c":3}
au

S = pd.Series(D)
/S

Print/sic])
/c
m

None of the above


co

48. Output of following code:


e.
ub

import numpy as np
ut

a=np.array([[1,2,3],4,5,6]])
yo

b=a.reshape(3,2)

print(b.size)

ANS:6

49. What will be the output?

from matplotlib import pyplot as plt

x= [1, 2, 3, 4, 5]
y=[1,2,3,4,5]

plt. xlabel("x axis")

plt. ylabel("'y axis")

plt.plot(x, v)

plt.show(0

A straight line

hi
at
vH
ra
au
/S

50. Choose the correct output for the following code:


/c
m

Import pandas as pd
co

D 'a:1,"b":2,"c":3}
e.
ub

S pd.Series(D)
ut

Print(S)
yo

a 1

b 2

C 3

dtype: int64

51. Consider the following code steps:

STEP 1: import pandas as pd


STEP2 data = {"Car": ["SCross", "Innova", "Santro"], "Manufacturer": ["Suzuki", "Toyota",
"Hyundai"],"Mileage": [24, 18, 22]}

STEP 3: d= pd.data.DataFrame(index=["Car1", "Car2", "Car3"])


STEP 4: print(d)

Which of the above code steps is incorrect?

Step1

Step2

Step3

Step4

hi
at
52. How to install numpy?
vH
ra
au

Pip-install numpy
/S
/c
m
co

53. DataFrame is
e.

A Two-dimensional data structure


ub
ut
yo

54-: import numpy as np

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

Print(a.size)

Ans-:6
55-: What will be the output of the following python code?

a-2

def fun(a=3):

a-5
print(a)
fun)

Ans-:5

hi
56. Assuming the credentials to be correct and the table students exists, choose the correct

at
statement for the following code vH
ra
au

import mysql.connector
/S
/c
m

mydb = mysql.connector.connect(
co
e.
ub

host "localhost",
ut
yo

user = "root",

passwd = "12345"

database = "myDB"

my_cursor = mydb.cursor(0
q = "INSERT INTO students(Name, RollNo, Course) VALUES(%s, %s, %s)"

V = [("XYZ", 123, "B.Tech. CSE")]

my cursor.execute(q, v)

mydb.commit)

Options:
insert XYZ, 123, and B.Tech to the columns Name, RollNo, and Course respectively
It will in the
students table

hi
at
It will give error as SQL command is not valid vH
ra
au

It gives error as there is a mismatch in the datatypes


/S
/c
m

None of the above


co
e.
ub

57. Which of the following SQL queries can be used to fetch the row(s) from a table students
ut

where Name is Sachin?


yo

SELECT FROM students WHERE Name "Sachin'

SELECT ALL FROM students WHERE Name = "Sachin'

SELECT* FROM students WHERE Name = 'Sachin'

SELECT FROM students WHERE Name == 'Sachin'


yo
ut
ub
e.
co
m
/c
/S
au
ra
vH
at
hi

You might also like