Rajat CS Assignment File
Rajat CS Assignment File
Submitted by - Submitted to –
Rajat Chaudhary Mr. Hemant Dixit
Class – XIIth C P.G.T (C.S)
Page 1 of 53
CERTIFICATE
Signature of Principal
______________
Page 2 of 53
ACKNOWLEDGEMENT
Rajat Chaudhary
Class: XIIth C
Page 3 of 53
TOPICS
1. Program to calculate the tax on the basis of salary and
total savings.
2. Program to calculate the simple interest and total
amount to be paid.
3. Program to calculate factorial of a number using while
loop.
4. Program to store students‟ information like admission
number, roll number, name and marks in a dictionary,
and display information on the basis of admission
number.
5. Program to count lowercase and uppercase letters in
an inputted string.
6. Program to calculate the product of two integers
without using “*” operator, instead using repeated
addition. floating numbers with no decimals.
7. Program to count and display vowels.
8. Program to remove duplicate from the list.
9. Program to get the largest number from list.
Page 4 of 53
10. Program of two lists and returns true if they have at
least one common member.
11. Write a program to pass student record as a
dictionary to a function and update their marks.
12. Write a program that fills a list with numbers. (Using
randint ()).
13. Program to find the max, min and mean value from
the inputted list.
14. Write a program to perform binary search using
randint().
15. Program on bubble sort.
16. Program on insertion sort.
17. Program to print the product of floating numbers
with no decimals.
18. Program to illustrate nested if, else through a four -
function calculator.
19. Program to calculate the sum of the digits of a
random three - digit number.
20. Program to input elements in a tuple and pass it to a
function to determine the total number of even and
Page 5 of 53
odd numbers in it.
21. Consider a databases LOANS in the question and
answer the question.
22. Consider the following tables PRODUCT and
CLIENT in the question and answer the question.
23. Consider the following tables COMPANY and
MODEL. Answer the following question.
24. Consider the following tables STOCK and DEALER.
Answer the following question.
25. Consider the following table CARDEN and answer
the following question.
26. To check whether the database has been created or
not using python interface.
27.Program to create a table „Student‟ inside the database
„School‟ using python interface.
28.To check the table is created or not.
29.To add a column in a given table.
30.To insert the record into the given table using python
interface.
Page 6 of 53
QUESTIONS AND THEIR
OUTPUTS
1. Program to calculate the tax on the basis of salary
and total savings.
The code are as follows:
basic = int(input("Enter the basic salary : "))
savings = int(input("Enter the total salary amount :
"))
if basic <= 500000:
if savings > 150000:
savings = 150000
tot_income = basic-savings-250000
tax = tot_income * 0.05
elif basic <= 1000000:
if savings > 150000:
savings = 150000
tot_income_5slab = 500000-savings-250000
Page 7 of 53
tot_income_20slab = basic-500000
tax = tot_income_5slab * 0.05 + tot_income_20slab *
0.02
else:
if savings > 150000:
savings = 150000
tot_income_5slab = 500000-savings-250000
tot_income_30slab = basic-1000000
tax = tot_income_5slab * 0.05 + tot_income_30slab *
0.03 + 100000
print("Total income tax to be paid = ",tax)
Output :
Page 8 of 53
2. Program to calculate the simple interest and total
amount to be paid.
The code are as follows :
Principal = eval(input("Enter the value of
principal : "))
Rate = eval(input("Enter the annual rate of interest :
"))
Time = int(input("Enter the time of interest : "))
Simple_int = Principal*Rate*Time/100
Amount = Principal+Simple_int
print("Simple Interest = ",Simple_int)
print("Amount payable = ",Amount)
Output :
Page 9 of 53
3. Program to calculate factorial of a number using
while loop.
The code are as follows :
num = int(input("Enter the number for
calculating its factorial : "))
fact = 1
i=1
while i<=num:
fact = fact*i
i=i+1
print("The factorial of ",num,"=",fact)
Output :
Page 10 of 53
4. Program to store students‟ information like
admission number, roll number, name and marks in a
dictionary, and display information on the basis of
admission number.
The code are as follows :
SCL=dict()
i=1
flag=0
n=int(input("Enter number of entries:"))
while i<=n:
Adm=input("\nEnter admission no of a student:")
nm=input("Enter name of the student:")
section=input("Enter class and section:")
per=float(input("Enter percentage of a student:"))
b=(nm,section,per)
SCL[Adm]=b
i=i+1
l=SCL.keys()
for i in l:
print("\nAdmno-",i,":")
z=SCL[i]
print("Name\t","class\t","per\t")
Page 11 of 53
for j in z:
print(j,end="\t")
Output :
Page 12 of 53
5. Program to count lowercase and uppercase letters
in an inputted string.
The code are as follows :
str1 = input("Enter the string : ")
print(str1)
uprcase = 0
lwrcase = 0
i=0
while i < len(str1):
if str1[i].islower() == True:
lwrcase += 1
if str1[i].isupper() == True:
uprcase += 1
i += 1
print("No. of uppercase letters in the string:
",uprcase)
print("No. of lowercase letters in the string :",
lwrcase)
Output :
Page 13 of 53
6. Program to calculate the product of two integers
without using “*” operator, instead using repeated
addition. floating numbers with no decimals.
The code are as follows :
n1 = float(input("Enter the first number : "))
n2 = float(input("Enter the second number : "))
prod = 0
i = n1
while i > 0:
i=i-1
prod = prod + n2
print("Product of",n1,"and",n2,"is",prod)
Output :
Page 14 of 53
7. Program to count and display vowels.
The code are as follows :
str1 = input("Enter the sentence : ")
str2 = str1.lower()
print(str2)
count = 0
List1 = ["a","e","i","o","u"]
for i in str2:
if i in List1:
count = count+1
print("No. of vowels in a given sentence : ",count)
Output :
Page 15 of 53
8. Program to remove duplicate from the list.
The code are as follows :
List1 = [10,20,30,20,10,50,60,40,80,50,40]
dup_iteams = []
uniq_iteams = []
for x in List1:
if x not in dup_iteams:
uniq_iteams.append(x)
dup_iteams.append(x)
print("No. of duplicate iteam in a list =
",dup_iteams)
Output :
Page 16 of 53
9. Program to get the largest number from list.
The code are as follows :
list1 = input("Enter the list : ")
def max_num_in_list(list1):
max = list1
for a in list1:
if a > max:
max = a
return max
print(max_num_in_list(list1))
Output:
Page 17 of 53
10. Program of two lists and returns true if they have
at least one common member.
The code are as follows :
list1 = input("Enter the first list = ")
list2 = input("Enter the second list = ")
for x in list1:
for y in list2:
if x == y:
result = True
else:
result = False
print(result)
Output :
Page 18 of 53
11. Write a program to pass student record as a
dictionary to a function and update their marks.
The code are as follows :
def Marks_increase(stud,P):
stud["Marks"]+=P
stud["Status"]="Updated"
student1={"Rollno":11,"Name":"Rishabh","Marks":95,"Status":"*"
}
student2={"Rollno":12,"Name":"Gaurav","Marks":90,"Status":"*"}
student3={"Rollno":13,"Name":"Radhika","Marks":89,"Status":"*"
}
Marks_increase(student1,60)
Marks_increase(student2,55)
Marks_increase(student3,58)
print(student1)
print(student2)
print(student3)
Page 19 of 53
Output :
Page 20 of 53
12. Write a program that fills a list with numbers.
(Using randint ()).
The code are as follows :
from random import randint
def fill_list(lst,limit_num,low,high):
for i in range(limit_num):
lst.append(randint(low,high))
minimum=int(input("Min:"))
maximum=int(input("Max:"))
n=int(input("Numbers limit:"))
a=[]
fill_list(a,n,minimum,maximum)
print(a)
Output:
Page 21 of 53
13. Program to find the max, min and mean value
from the inputted list.
The code are as follows :
list1 = []
n = int(input("Enter the number of elements in the
list : "))
i=0
while i < n:
x = int(input("Enter the elements of the list : "))
list1.append(x)
i=i+1
print(list1)
maximum = max(list1)
minimum = min(list1)
mean = sum(list1)/len(list1)
print("Maximum value is ",maximum)
print("Minimum value is ",minimum)
Page 22 of 53
print("Mean value is ",mean)
Output:
Page 23 of 53
14. Write a program to perform binary search using
randint().
The code are as follows :
from random import randint
def bin_search(lst,item):
mid=len(lst)//2
low=0
high=len(lst)-1
while lst[mid]!=item and low<=high:
if item>lst[mid]:
low=mid+1
else:
high=mid-1
mid=(low+high)//2
if low>high:
return None
else:
return mid
a=[]
for i in range(10):
a.append(randint(1,20))
a.sort()
Page 24 of 53
print(a)
value=int(input("Enter the number to be
searched:"))
print("Element found at the
index:",bin_search(a,value))
Output :
Page 25 of 53
15. Program on bubble sort.
The code are as follows :
def main():
l = [42, 29, 74, 11, 65, 58]
n = len(l)
print("Original list : ",l)
for i in range(n-1):
for j in range(n-i-1):
if l[j] > l[j+1]:
l[j], l[j+1] = l[j+1], l[j]
print("List after sorting is : ",l)
Output :
Page 26 of 53
16. Program on insertion sort.
The code are as follows :
a = [70, 49, 31, 6, 65, 81, 68]
print("Original list : ",a)
for i in a:
j = a.index(i)
while j > 0:
if a[j-1] > a[j]:
a[j-1] , a[j] = a[j] , a[j-1]
else:
break
j = j-1
print("List after sorting : ",a)
Output :
Page 27 of 53
17. Program to print the product of floating numbers
with no decimals.
The code are as follows :
val1 = float(input("Enter the first no. = "))
val2 = float(input("Enter the second no. = "))
product = val1 * val2
print("The product of the float no. = ",product)
Output :
Page 28 of 53
18. Program to illustrate nested if, else through a four -
function calculator.
The code are as follows :
result = 0
val1 = float(input("Enter the value 1 : "))
val2 = float(input("Enter the value 2 : "))
op = input("Enter any of the operator (+,-,*,/) : ")
if op == "+":
result = val1 + val2
elif op == "-":
if val1 > val2:
result = val1 - val2
else:
result = val2 - val1
elif op == "*":
result = val1 * val2
elif op == "/":
if val2 == 0:
print("Please enter the valid value other than 0")
else:
result = val1 / val2
else:
Page 29 of 53
print("Please enter any other of the operator (+,-
,*,/) : ")
print("The result is : ",result)
Output :
Page 30 of 53
19. Program to calculate the sum of the digits of a
random three - digit number.
The code are as follows :
from random import random
a = n//100
b = (n//10)%10
c = n % 10
print(a+b+c)
Output :
Page 31 of 53
20. Program to input elements in a tuple and pass it to
a function to determine the total number of even and
odd numbers in it.
The code are as follows :
def countevenodd(tup):
counteven = 0
countodd = 0
for i in tup:
if i % 2 == 0:
counteven += 1
else:
countodd += 1
return counteven, countodd
tup1 = ()
n = int(input("Enter the total elements in a tuple :
"))
for i in range(n):
num = int(input("Enter the number : "))
tup1 = tup1 + (num,)
count_stats = countevenodd(tup1)
print("Even numbers are : ",count_stats[0])
print(“Odd numbers are :”,count_stats[1])
Page 32 of 53
Output :
Page 33 of 53
21. Consider a databases LOANS with the following
tables.
Table: LOANS
Page 34 of 53
Answer the following question:
i. Display the sum of all loan amount whose interest
rate is greater than 10.
ii. Display the maximum interest from loan table.
iii. Display the count of all loan holders whose interest
rate is NULL.
iv. Display the count of all loan holders whose name
ends with „Sharma‟.
Page 35 of 53
iii. Mysql> SELECT COUNT (*) FROM LOANS
WHERE Int_Rate IS NULL;
Page 36 of 53
22. Consider the following tables PRODUCT and
CLIENT in the question and answer the question.
Table: PRODUCT
Table: CLIENT
C_ID Client Name City P_ID
01 Cosmetic Delhi FW05
shop
02 Total Health Mumbai BS01
03 Live Life Delhi SH06
04 Pretty Woman Delhi FW12
Page 37 of 53
05 Dreams Bengaluru TP01
Page 38 of 53
iii.
iv.
Page 39 of 53
23. Consider the following tables COMPANY and
MODEL. Answer the following question.
Table: Company
Comp_ID CompName CompHO ContactPerson
1 Titan Okhla C.B. Ajit
Table: Model
Page 40 of 53
Answer the Following Questions:
i. To display details of all models in the Model
table in ascending order of
DateOfManufacture.
ii. To display details of those models
manufactured in 2011 and whose Cost is
below 2000.
iii. To decrease the cost of all the models in
Model table by 15%.
iv. SELECT COUNT (DISTINCT CompHO)
FROM Company;
Ans:
i. SELECT * FROM MODEL ORDER BY
DateOfManufacture;
Page 41 of 53
ii. SELECT * FROM MODEL WHERE year
(DateOfManufacture)=2011 AND
Cost<2000;
iv.
Page 42 of 53
24. Consider the following tables STOCK and
DEALER. Answer the following question.
Table: Stock
ItemNo Item Dcode Qty UnitPrice StockDate
5005 Ball Pen 0.5 102 100 16 2011-03-31
Page 43 of 53
104 Fair Deals
Page 44 of 53
ii. SELECT * FROM STOCK WHERE Dcode=102
OR Qty>100;
iii.
iv.
Page 45 of 53
25. Consider the following table CARDEN and answer
the following question.
Table : GARDEN
Ccod CarNam Make Color Capacit Charge
e e y s
501 A-Star Suzuki RED 3 14
503 Indigo Tata SILVE 3 12
R
502 Innova Toyota WHIT 7 15
E
509 SX4 Suzuki SILVE 4 14
R
510 C Class Mercede RED 4 35
s
Answer the Following Questions:
i. To display the names of all the silver-coloured
cars.
ii. To display name, make and capacity of cars in
descending order of their sitting capacity.
iii. To display the highest charges at which a vehicle
can be hired from CARDEN.
Page 46 of 53
Ans:
i. SELECT CarName FROM CARDEN WHERE
Color LIKE „SILVER‟;
Page 47 of 53
26. To check whether the database has been created or
not using python interface.
The Code are as follows:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",pa
sswd="123456")
mycursor=mydb.cursor()
mycursor.execute("CREATE DATABASE school")
mycursor.execute("SHOW DATABASES")
for x in mycursor:
print(x)
Output
Page 48 of 53
27. Program to create a table „Student‟ inside the
database „School‟ using python interface.
The Code are as follows:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="123456",\
database="school")
mycursor=mydb.cursor()
mycursor.execute("CREATE TABLE student(Rollno
int(3) Primary Key,\
Name varchar(15),Age integer, City char(8))")
OUTPUT
Page 49 of 53
28. To check the table is created or not.
The Code are as follows:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="123456",\
database="school")
mycursor=mydb.cursor()
mycursor.execute("SHOW TABLES")
for x in mycursor:
print(x)
OUTPUT:
Page 50 of 53
29.To add a column in a given table.
The code are as follows:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="123456",\
database="school")
mycursor=mydb.cursor()
mycursor.execute("Alter table student add(Marks
int(3))")
OUTPUT:
Page 51 of 53
30. To insert a record into the given table using Python
Interface.
The Code are as follows:
import mysql.connector
mydb=mysql.connector.connect(host="localhost",\
user="root",\
passwd="123456",\
database="school")
mycursor=mydb.cursor()
mycursor.execute("INSERT INTO student
VALUES(1,'Tarun',23,'Mumbai',398)")
mydb.commit()
print(mycursor.rowcount,"Record Inserted")
OUTPUT:
Page 52 of 53
Page 53 of 53