0% found this document useful (0 votes)
22 views

UT XII July 2023 Set 2 With Answers

test

Uploaded by

laxmi567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

UT XII July 2023 Set 2 With Answers

test

Uploaded by

laxmi567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

SET B

ARMY PUBLIC SCHOOL, DHAULA KUAN


CLASS: XI SUBJECT : COMPUTER SCIENCE
TIME: 1HR M.M: 30
General Instructions:
1. All programming questions to be answered using Python language only.
2. All questions are compulsory.
Q) In SQL, the equivalent of UCASE () is: [1]

a) UPPERCASE () b) CAPITALCASE() c) UPPER() d) TITLE()

ans (c) upper()

Q Q Evaluate the following statement and write output: [1]

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:

myexam="@@CBSE Examination 2022@@" [1]

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]

Book={1:'Thriller', 2:'Mystery', 3:'Crime', 4:'Children Stories'}

Library ={'5':'Madras Diaries','6':'Malgudi Days'}

(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.

c) Write an SQL statement to count the products city wise.

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.

Ans. a) SELECT NAME FROM COMPANY ORDER BY NAME DESC;

b) ALTER TABLE CUSTOMER ADD TOTAL_PRICE DECIMAL(10,2);

c) SELECT COUNT(*), CITY FROM COMPANY GROUP BY CITY;

d) SELECT CUSTOMER.NAME, UNITPRICE*QTY, PRODUCTNAME FROM COMPANY,CUSTOMER WHERE


COMPANY.PID=CUSTOMER.PID AND CITY= 'MUMBAI';

Q Consider the table CLUB given below and write the output of the SQL queries that follow. [1X3=3]

CID CNAME AGE GENDER SPORTS PAY DOAPP

5246 AMRITA 3 FEMALE CHESS 900 3/27/2006

4687 SHYAM 37 MALE CRICKET 1300 4/15/2004

1245 MEENA 23 FEMALE VOLLEY BALL 1000 6/18/2007

1622 AMRIT 28 MALE KARATE 1000 9/5/2007

1256 AMINA 36 FEMALE CHESS 1100 8/15/2003

1720 MANJU 33 FEMALE KARATE 1250 4/10/2004

2321 VIRAT 35 MALE CRICKET 1050 4/30/2005

(i) SELECT COUNT(DISTINCT SPORTS) FROM CLUB;

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

CNAME AGE PAY

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

for C in range (NUM,1,-1):

NAVG=NAVG + NAV[C]

print (NAVG)

i) YELLOWBLUEGREEN (ii) YELLOWBLUE

(iii) YELLOW (iv) REDGREENBLUE

Ans (ii) YELLOWBLUE

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

corrections made. [2]

def sumdigits(n):

d=0

for x in str(n):

d=d+x

return d

n=int(input(‘Enter any number”))

s=sumdigits(n)

print(“Sum of digits”,s)

Ans

def sumdigits(n):

d=0

for x in range(n): #range function should use in place of str()

d=d+x #indented block after for loop

return d #return outside function

n=int(input("Enter any number")) #use of single quote at the beginning


s=sumdigits(n)

print("Sum of digits",s)

Q Find Output: [2+2]

(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]

rno(Roll number )- integer

name(Name) - string

DOB (Date of birth) – Date

Fee – float

Note the following to establish connectivity between Python and MySQL:

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

import mysql.connector as mysql

con1=mysql.connector(host='localhost',user='root',password='tiger',database='school')

mycursor=con1.cursor()

rno=int(input('enter roll number for updation:'))

name=input('enter the name')

dob=input('enter date of birth')

fee=float(input('enter fee:'))

mycursor.execute("update student set name='{}',dob='{}',fee={} where


rno={})".format(name,dob,fee,rno))

con1.commit()

con1.close()

You might also like