INT213 Answer Key
INT213 Answer Key
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
s1="Hello World"
s2=is1-3:-7-1]
print(s)
Ans-: roW
If (3-4//2):
print("Hello")
else:
hi
at
print("Hii") vH
ra
au
Ans-: Hello
/S
/c
m
correct option:
ub
ut
a.insert(50, 3)
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.insert(10, 3)
hi
*
at
vH
ra
au
/S
/c
m
co
e.
ub
Ans-: 0
ut
yo
option:
s1="Hello World"
S2=S1
ld of s1 and s2 is same.
ld of s1 and s2 is different.
None of these
protected
hi
ind
at
variable name
vH
ra
au
Ans-
/S
/c
m
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
Both name1 and name2 will have reference to two different objects of class Name
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-
Class Name:
Count = 0
self.x
Name.count t I
rint(namel.
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
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
a = 4//2
b 4//0
C 4//4
printa)
print(b)
print(c)
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
Q18-: Consider a file "MyFile. txt" saved in the local/working directory, which of the following
ub
import pickle
f open("myfile.txt", "w")
pickle. dump("Python", f)
pickle. dump("Programming", f
f.close0
print(pickle.load(f))
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
top Tk)0
top.geometry("250x250")
label.pack0
top.mainloop)
Ans : It will create a label with "Welcome" labelled on it and pack it on the window
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.
root Tk ()
ut
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
Q25-: In the GUI programming, origin of the coordinate system is specified by the
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 .
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
import pickle
e.
ub
pickle. dump(123.45, f)
f.close)
f open("myfile.txt", "rb")
print(pickle.load(f))
Ans-: 123.45
=open (
"myfile8. txt'", "w")
I .Close ()
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) "
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
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.
my cursor.execute(query)
ut
yo
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)
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
33. What SQL command will be used if you want to delete an existing table named as students?
yo
OPTIONS:
DROP students
34. Which of the following is the correct statement for numpy?
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
host "localhost",
user = "root",
passwd= "abc@123"
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.
hi
at
36. The SQL command to create a database "mydatabase" is vH
ra
CREATE DATABASE mydatabase
au
/S
/c
m
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()
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()
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
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
Import pandas as pd
/c
"manufacturer":["Suzuki","toyota","Hyundai"l,
e.
"mileage":[24,18,22]
ub
ut
yo
D pd.DataFrame(data,index = ["car1","car2","car3"])
Print(type(D))
import pandas as pd
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-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:
x= (1, 2, 3, 4, 5)
hi
at
plt. ylabel("y axis") vH
ra
au
plt.plot(x, y)
/S
/c
m
plt.show()
co
e.
ub
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
y np.sin(x)
pit.plot(x,y)
pit show()
the following code will correspond to
Sin wave
Straight line
Ellipse
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
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
x= [1, 2, 3, 4, 5]
y=[1,2,3,4,5]
plt.plot(x, v)
plt.show(0
A straight line
hi
at
vH
ra
au
/S
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
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=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)"
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
57. Which of the following SQL queries can be used to fetch the row(s) from a table students
ut