UT XII July 2023 Set 2 With Answers
UT XII July 2023 Set 2 With Answers
print(15.0 / 4 + (8 + 3.0))
Ans 14.75
Q Consider the statements given below and then choose the correct output from the given options:
print(myexam[::-2])
(a) @20 otnmx SC@ (b) @22niaiaESC@ (c) @22niaiaE SC@ (d) @20otnmxSC@
Ans (a)
Q Which of the following will delete key-value pair for key = “Red” from a dictionary D1? [1]
a. delete D1("Red") b. del D1["Red"] c. del.D1["Red"] d. D1.del["Red"]
Ans (b)
del D1["Red"]
Q Consider the following code and answer the questions that follow: [1+1=2]
(a) . Ramesh needs to change the title in the dictionary book from ‘Crime’ to ‘Crime Thriller’. He has
written the following command:
Book[‘Crime’]=’Crime Thriller’
But he is not getting the answer. Help him choose the correct command:
i. Book[2]=’Crime Thriller’
ii. Book[3]=’Crime Thriller’
iii. Book[2]=(’Crime Thriller’)
iv. Book[3] =(‘Crime Thriller’)
Correct Answer: ii
(b). The command to merge the dictionary Book with Library the command would be:
i. d=Book+Library
ii. print(Book+Library)
iii. Book.update(Library)
iv. Library.update(Book)
Correct Answer: iv
Q A database called ecompany has two tables COMPANY and CUSTOMER with the following records.
Write SQL commands for the queries (a)-(d) based on the two tables COMPANY and CUSTOMER
COMPANY [1x4=4]
PI PRODUCT
D NAME CITY NAME
21
01 APPLE DELHI WATCH
21 SAMSU BANGA
02 NG LORE MOBILE
21 PANAS
03 ONIC DELHI TV
21 MUMB
04 SONY AI MOBILE
21 LENOV INDOR
05 O E TABLET
21 MUMB
06 DELL AI LAPTOP
CUSTOMER
CUSTI
D NAME UNIT PRICE QTY PID
101 REENA SONI 60,000 10 2102
102 MICHAEL PAUL 50,000 20 2106
103 MEETALI SINGH 70,000 15 2101
104 PARUL SOHAL 55,000 3 2103
105 RAJESH DESWAL 45,000 7 2104
a) Write an SQL statement to display the name of the companies in reverse alphabetical order.
b) To add one more column to the table customer called TOTAL_PRICE which can have up to two
decimal places.
d) Write an SQL statement to display the customer name, product of the unit price and quantity,
product name where the name of the city is Mumbai.
Q Consider the table CLUB given below and write the output of the SQL queries that follow. [1X3=3]
(ii) SELECT CNAME, SPORTS FROM CLUB WHERE DOAPP<"2006-04-30" AND CNAME LIKE "%NA";
(iii) SELECT CNAME, AGE, PAY FROM CLUB WHERE GENDER = "MALE" AND PAY BETWEEN 1000 AND
1200;
Ans
(i)
COUNT(DISTINCT SPORTS)
4
(ii)
CNAME SPORTS
AMINA CHESS
(iii)
AMRIT 28 1000
VIRAT 35 1050
Q Write a function, lenWords(STRING), that takes a string as an argument and returns a tuple containing
length of each word of a string.
For example, if the string is "Come let us have some fun", the tuple will have (4, 3, 2, 4, 4, 3) [3]
Ans
def lenwords(string):
t=()
L=string.split()
for i in L:
length=len(i)
t=t+(length,)
return t
Q In a table in MYSQL database, an attribute A of datatype varchar(20) has the value “Keshav”. The
attribute B of datatype char(20) has value “Meenakshi”. How many characters are occupied by attribute
A and attribute B? [1]
ans 6,20
Q What are the possible outcome(s) executed from the following code? Also specify the maximum and
minimum values that can be assigned to variable N. [1+1]
import random
NAV = ['RED','GREEN','BLUE','YELLOW']
NUM =random.randint(1,3)
NAVG=NAVG + NAV[C]
print (NAVG)
Q Raman has written a code to find its sum of digits of a given number passed as parameter to
function sumdigits(n). His code is having errors. Rewrite the correct code and underline the
def sumdigits(n):
d=0
for x in str(n):
d=d+x
return d
s=sumdigits(n)
print(“Sum of digits”,s)
Ans
def sumdigits(n):
d=0
print("Sum of digits",s)
(a) (b)
def Display(str): a = 10
m="" print(a*3)
for i in range(0,len(str)): def fun1(a):
if(str[i].isupper()): def fun2():
m=m+str[i].lower() print("hello")
elif str[i].islower(): print("hello")
m=m+str[i].upper() print(a*2)
else: fun1(a)
if i%2==0: print(a)
m=m+str[i-1]
else: Ans
m=m+"#" 30
print(m) hello
20
Display('[email protected]') 10
Ans fUN#pYTHONn#.
Q State the difference between Local variables and global variables with the help of an example. [2]
Ans
those variable which r defined inside the function or in the parameter-local variable
those variable which r defined outside the function are called global variable
x=1
def cg():
global x
x=3
x=x+1
print(x)
cg()
print(x)
Q Kabir wants to write a program in Python to update the following record according to the rollno
entered by the user in the table named Student in MYSQL database, SCHOOL: [3]
name(Name) - string
Fee – float
Username - root
Password - tiger
Host - localhost
The values of fields rno, name, DOB and fee has to be accepted from the user. Help Kabir to write the
program in Python.
Ans
con1=mysql.connector(host='localhost',user='root',password='tiger',database='school')
mycursor=con1.cursor()
fee=float(input('enter fee:'))
con1.commit()
con1.close()