12 B Cs Tanush
12 B Cs Tanush
Science
Practical
File
NAME – Tanush Goyal
Class – XII-B
INDEX
S.No. Question Type Remarks
Output:
A1
''' Tanush Goyal
12B
'''
acno = int(input("Enter account number: "))
acna = input("Enter account holder name: ")
while True:
acty = input("Enter account type(s/c): ")
if acty == 's' or acty == 'c':
break
else:
print('''
Acount type caan only be --> s or c
Please enter again ''')
while True:
acbal = eval(input("Enter opening balance(min 1000): "))
if acbal >= 1000:
break
else:
print('''
Minimum opening balance is 1000
Please enter again ''')
while True:
print('''
1. Display report
2. Deposit money
3. Withdraw money
4. Exit''')
ask = int(input("Enter the number of task(1,2,3,4) : "))
if ask==1:
print("account number"," ",acno) and print("account holder name"," ",acna)
print("account type"," ",acty) and print("account balance"," ",acbal)
elif ask==2:
dep = eval(input("Enter the amount of money to be deposited: "))
acbal+=dep
print("Account balance = ",acbal)
elif ask==3:
withdraw = eval(input("Enter the amoount of money to withdraw: "))
while True:
if acbal<1000:
print('Your acount balance is less than 1000 please deposit some money')
break
elif withdraw>(acbal-1000):
print("you are withdrawing money more than you account balance - 1000")
break
else:
acbal-=withdraw
print("Successfully done a withdrawl of ",withdraw,"account balance left",acbal)
break
elif ask==4:
break
else:
print("Enter numbers only from 1,2,3,4 ")
Q2 Write a python program to obtain percentage of a student and assign him grade according to
the following criteria
Percentage Grade
80-100 A
60-80 B
40-60 C
<=40 D
Output:
A2
'''
Tanush Goyal
12B
'''
pr= eval(input("Enter your percentage: "))
if pr>80 and pr<=100:
print("A Grade")
elif pr>60 and pr<=80:
print("B Grade")
elif pr>40 and pr<=60:
print("C Grade")
elif pr<=40:
print("D Grade")
Q3 Write a python program to obtain the values of x and n and then display the sum of the
following series:
Output:
A3
'''
Tanush Goyal
12B
'''
sum=0
for i in range(2,n+1,2):
f=1
for j in range(2,i+1):
f*=j
sum += (((-1)**(i-1))*(x**i))/f
print(x+sum)
Q4 Write a python program to obtain a number from the user and then display all the palindrome
up to this number?
Output:
A4
'''
Tanush Goyal
12B
'''
n=int(input("Enter number:"))
for i in range(0,n+1):
temp=i
rev=0
while(i>0):
dig=i%10
rev=rev*10+dig
i=i//10
if(temp==rev):
print(temp)
Q5 Write a python program to calculate all the Armstrong numbers between 0-1000
Output:
A5
'''
Tanush Goyal
12B
'''
print("Armstrong numbers between 0 to 1000: \n")
Output:
A6
'''
Tanush Goyal
12B
'''
start = int(input("Enter the starting number: "))
end = int(input("Enter the ending number: "))
Output:
A7
'''
Tanush Goyal
12B
'''
b_int = ""
b_frac = ""
Output:
A8
'''
Tanush Goyal
12B
'''
a = input("Enter a string: ")
b = input("Enter a letter: ")
l=len(a)
c=0
for i in range(0,l):
if a[i]==b:
print("Found at",i,"the position")
c=c+1
print("Total",c,"times")
Q9 Write a program to obtain number of students, their roll number, marks of each from the user
and then store it into a dictionary and print the following
1. The dictionary
2. Average Marks
3. Total Marks
4. Maximum Marks
Output:
A9
'''
Tanush Goyal
12B
'''
d={}
n=int(input("Enter the number of students: "))
s=mx=0
for i in range(1,n+1):
r=int(input("Enter the roll number: "))
m=int(input("Enter the Marks: "))
d[r]=m
s+=m
if m>mx:
mx=m
print("List of student:",d)
print("Average marks: ",s/n)
print("Total marks: ",s)
print("Maximum marks: ",mx)
Q10 Write a program to obtain product number, cost of each 4 products from the user and then
store it into a dictionary and print the following:
1. Dictionary
2. Average cost
3. Total cost
4. Maximum cost
5. Also ask the user f he wants to add more details of how much products, their number and
their cost and then print the final dictionary
Output:
A10
'''
Tanush Goyal
12B
'''
d={}
a=b=s=0
for i in range(1,5):
n=int(input("Enter product number: "))
c=eval(input("Enter the cost of product: "))
d[n]=c
s+=c
if c>s/4:
b=b+1
elif c<s/4:
a=a+1
print("\n\n")
print("Product details: ",d)
print("Average product cost: ",s/4)
print("Products above average: ",b)
print("Products below average: ",a)
print("\n\n")
new= input("Do you want to add more produts(Y/N): ")
while new=='Y':
print("\n\n")
print("New product detail list: ",d)
Q11 MYSQL
Database name – School , Table name - Book
Bno Bname Subject Author Cost
1 Easy CS CS Vidyapeeth 190
2 MySQL CS NCERT 250
3 Python CS NCERT 500
4 Maths Part 1 Maths NCERT 350
5 Physics English NCERT 246
6 Maths Part 2 Maths 467
7 Cengage 908
8 Chemistry Part 1 Chemistry NCERT 676
9 Chemistry part 2 Chemistry NCERT 765
10 Pharmaceutical Biology 543
2. Select Bno,Bname,Cost*10/100”Discount”
From Book
Where Author = “NCERT”;
4. Select *
From Book
Where Author = “NCERT and Cost between 300 and 800;
6. Select *
From Book
Where Author = “NCERT” order by Cost;
8. Select *
From Book;
2. Select *
From Manager
Where Ename like “D%” order by salary asc;
6. Update Manager
Set Salary = 600000
Where Post = “Junior Manager”;
7. Update Manager
Set Post = “Cashier” , Salary = 45000
Where Ename = “Shivam Bansal”;
8. Delete
From Manager
Where Ename = “Shourya Gupta”
9. Select Post
From Manager
Where Salary >= 5000
Group by Post;
02 Pencil 40 Doms
03 Water colours 45 Camlin
06 File 30 Lotus
07 Eraser 10 Doms
1. Select *
From Stationery;
2. Select P_name,Price
from Stationery
where manufacturer = “camlin”;
3. Update stationery
set price = price+10;
4. Select*
from stationery
order by price disc;
5. Delete
from stationery
where price < 40;
6. Select*
from stationery
where manufacturer like “_ _ _ _ _ _ “;
9. Select count(*)
from stationery;
2. SELECT *
FROM questions
ORDER BY difficulty_level DESC LIMIT 1;
4. SELECT answer_text
FROM answers
WHERE question_id = 3;
5. SELECT *
FROM questions
WHERE difficulty_level = 'Medium';
9. SELECT *
FROM questions
WHERE subject = ‘Computer Science’ AND chapter = ‘DBMS’;
2. SELECT *
FROM Students WHERE student_id = 3;
3. SELECT *
FROM Students WHERE section = 'A';
5. SELECT COUNT(*)
FROM Students;
6. SELECT AVG(age)
FROM Students;
9. SELECT Students.*
FROM Students,Grades
WHERE Students.student_id = Grades.student_id and Grades.grade = 'A' AND
Grades.subject = 'Math';
Output:
A16
'''
Tanush Goyal
12B
'''
def vowel(a):
l=len(a)
c=0
for i in range(0,l):
if a[i] in 'AEIOU':
c=c+1
print(c)
pattern(c)
def pattern(c):
for i in range(1,c+1):
for j in range(1,i+1):
print("*",end=" ")
print()
x=input("enter a string=")
vowel(x)
Q17 Write a program to obtain employee number and salary in dictionary as a key-value pair and
pass this dictionary as an argument in a function for some employees of company depending
upon user and then return the employee number with max salary and also how many employees
are earning below average salary.
Output:
A17
'''
Tanush Goyal
12B
'''
Output:
A18
'''
Tanush Goyal
12B
'''
def fun1(num):
r=0
s=0
m=num
while num!=0:
r=num%10
s=s*10+r
num//=10
if s==m:
return "yes"
else:
return "no"
n = int(input("enter a number "))
result=fun1(n)
print("the number is palindrome or not?-",result)
Q19 Write a program to have a user-defined function compare which obtain 3 integer arguments
and return the max argument and by how much from other two numbers
Output:
A19
'''
Tanush Goyal
12B
'''
def compare(a,b,c):
if a>b and a>c:
mx=a
d1=a-b
d2=a-c
elif b>a and b>c:
mx=b
d1=b-a
d2=b-c
elif c>a and c>b:
mx=c
d1=c-a
d2=c-b
return mx,d1,d2
x=int(input("enter num="))
y=int(input("enter num="))
z=int(input("enter num="))
p,q,r=compare(x,y,z)
print("max num=",p)
print("diff 1=",q)
print("diff2=",r)
Q20 Write a Python function named find_max that takes a list of numbers as a parameter and
finds the maximum value in the list. The function should return the maximum value.
Output:
A20
'''
Tanush Goyal
12B
'''
def find_max(numbers):
maximum = numbers[0]
for num in numbers:
if num > maximum:
maximum = num
return maximum
Output:
A21
'''
Tanush Goyal
12B
'''
my_list = [5, 2, 8, 1, 3]
sorted_list = sorted(my_list, reverse=True)
second_largest = sorted_list[1]
print("Second largest number:", second_largest)
Q22 Write a Python program to reverse the elements of a list without using the built-in reverse
function.
Output:
A22
'''
Tanush Goyal
12B
'''
my_list = [1, 2, 3, 4, 5]
reversed_list = my_list[::-1]
print("Reversed list:", reversed_list)
Q23 Write a Python program to find the common elements between two lists.
Output:
A23
'''
Tanush Goyal
12B
'''
list1 = [1, 2, 3, 4, 5]
list2 = [4, 5, 6, 7, 8]
common_elements = [element for element in list1 if element in list2]
print("Common elements:", common_elements)
Q24 Write a Python program to remove the nth occurrence of a specified element from a list.
Output:
A24
'''
Tanush Goyal
12B
'''
my_list = [1, 2, 3, 2, 4, 1, 5]
element = 2
occurrence = 2
count = 0
new_list = []
for item in my_list:
if item == element:
count += 1
if count != occurrence:
new_list.append(item)
else:
new_list.append(item)
print("List after removing nth occurrence:", new_list)
Q25-Write a program to have a user-defined function compare which obtain 3 integer arguments
and return the max argument and by how much from other two numbers and then store this data
in a file compare.txt and in the same program display the contents of the file.
Output:
A25
'''
Tanush Goyal
12B
'''
def compare(a,b,c):
mx=a
d1=a-b
d2=a-c
mx=b
d1=b-a
d2=b-c
mx=c
d1=c-a
d2=c-b
return mx,d1,d2
x=int(input("enter num="))
y=int(input("enter num="))
z=int(input("enter num="))
p,q,r=compare(x,y,z)
print("max num=",p)
print("diff 1=",q)
print("diff2=",r)
l=[x,y,z]
file=open("compare.txt","w")
for i in range(0,3):
file.write(str(l[i]))
file.write(" \n")
file.write("output:-\n")
file.write("max num:"+str(p)+"\n")
file.write("diff1:"+str(q)+"\n")
file.write("diff2:"+str(r)+"\n")
file.close()
g=open("compare.txt")
print("contents of file")
pr=g.read()
print(pr)
Q26-Write a program to obtain characters from the user till user enter “-1” & store all capital
characters to “upper.txt”,small letters to “lower.txt”, digits to “digits.txt” and other characters to
“others.txt”.
Output-
A26
'''
Tanush Goyal
12B
'''
up=open("upper.txt","w")
low=open("lower.txt","w")
dig=open("digits,txt","w")
ot=open("others.txt","w")
while True:
n=input("enter character=")
if n=="-1":
break
elif n>="A" and n<="Z":
up.write(n)
elif n>="a" and n<="z":
low.write(n)
elif n.isdigit():
dig.write(n)
else:
ot.write(n)
up.close()
low.close()
dig.close()
ot.close()
print("values entered in files")
Q27-Write a menudriven program to have a binary file which consists of emp no, emp name and
salary and do the following operations on it- create,read,modify,search,delete.
Output-
A27
import pickle
'''
Tanush Goyal
12B
'''
def add(f):
file=open(f,"wb+")
s=[]
for i in range(1,n+1):
s.append([empno,name,sal])
pickle.dump(s,file)
file.close()
def read(f):
file=open(f,"rb+")
data=pickle.load(file)
print(data)
file.close()
def modify(f):
file=open(f,"rb+")
data=pickle.load(file)
for i in data:
if i[1]==name:
file.seek(0)
pickle.dump(data,file)
file.close()
def search(f):
file=open(f,"rb+")
data=pickle.load(file)
print(i[1])
file.close()
def delete(f):
file=open(f,"rb+")
data=pickle.load(file)
s=[]
print(data)
for i in data:
if i[0]!=empno:
s.append(i)
print(s)
file.seek(0)
pickle.dump(s,file)
file.close()
print("Deletion successful")
ch='y'
if choice==1:
add(f)
elif choice==2:
read(f)
elif choice==3:
modify(f)
elif choice==4:
search(f)
elif choice==5:
delete(f)
else:
print("Invalid input")
ch=input("Do you want to continue?(Y/N)")
Q28-Write a program to count no. of records in a csv file- “products.csv” containing product
no.,name and quantity.
Output-
import csv
'''
Tanush Goyal
12B
'''
file=open("products.csv","r")
data=csv.reader(file)
c=0
for i in data:
c+=1
print("the no. of records are",c)
file.close()
Q29-Vedika has created a dictionary containing names and marks as key-value pairs of 5
students. Write a program, with separate user-defined functions to perform the following
operations:
1. Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 70.
2. Pop and display the content of the stack.
Dictionary is : d={"Ramesh":58, "Umesh":78, "Vishal":90, "Khushi":60, "Ishika":95}
Output-
'''
Tanush Goyal
12B
'''
def push(stk,item):
stk.append(item)
def Pop(stk):
if stk==[]:
return None
else:
return stk.pop()
stk=[]
d={"Ramesh":58, "Umesh":78, "Vishal":90, "Khushi":60, "Ishika":95}
for i in d:
if d[i]>70:
push(stk,i)
while True:
if stk!=[]:
print(Pop(stk),end=" ")
else:
break
Q30 Write a python connectivity program to create a menu driven program performing addition ,
updating ,deletion and displaying of all the data in the table .
Host – localhost
User – root
Password – root
Database – school
Table structure – id: integer, primary key
- name character
- age integer
Output:
A30 import mysql.connector
db = mysql.connector.connect(
host="localhost",
user="root",
password="root",
database="school"
)
def insert_data():
student_id = int(input("Enter student ID: "))
name = input("Enter name: ")
age = int(input("Enter age: "))
cursor = db.cursor()
query = "INSERT INTO students VALUES (%s, %s, %s)"
values = (student_id,name, age)
cursor.execute(query, values)
db.commit()
print("Data inserted successfully!")
def update_data():
student_id = int(input("Enter student ID: "))
ask = input("Want to edit name(n) or age(a) or both(b): ")
if ask=="n" or ask=="N":
new_name = input("Enter new_name: ")
cursor = db.cursor()
query = "UPDATE students SET name = %s WHERE id = %s"
values = (new_name, student_id)
cursor.execute(query, values)
db.commit()
elif ask=="a" or ask=="A":
new_age = int(input("Enter new age: "))
cursor = db.cursor()
query = "UPDATE students SET age = %s WHERE id = %s"
values = (new_age, student_id)
cursor.execute(query, values)
db.commit()
elif ask=="b" or ask=="B":
new_age = int(input("Enter new age: "))
new_name = input("Enter new_name: ")
cursor = db.cursor()
query = "UPDATE students SET age = %s , name = %s WHERE id = %s"
values = (new_age, new_name, student_id)
cursor.execute(query, values)
db.commit()
def display_data():
cursor = db.cursor()
query = "SELECT * FROM students"
cursor.execute(query)
result = cursor.fetchall()
for row in result:
print(f"ID: {row[0]}, Name: {row[1]}, Age: {row[2]}")
while True:
print("\nMenu:")
print("1. Insert Data")
print("2. Update Data")
print("3. Display Data")
print("4. Quit")
if choice == 1:
insert_data()
elif choice == 2:
update_data()
elif choice == 3:
display_data()
elif choice == 4:
print("Goodbye")
break
else:
print("Invalid choice. Please select a valid option.")