Computer Record XII B 2024 PDF
Document Details
Uploaded by ComfyCitrine1195
Gulf Asian English School, Sharjah
Raina Maria Koshy
Tags
Summary
This document is a computer science past paper for class XII B. It contains Python programming questions and solutions, including problems involving factorial, prime numbers, and palindrome checking.
Full Transcript
COMPUTER RECORD Name: Raina Maria Koshy Class: XII B Roll no: 19 PROGRAM 1 Objective: Write a menu driven Python program using function to: a. Find the factorial of a number. b. Print first ‘n’ Prime...
COMPUTER RECORD Name: Raina Maria Koshy Class: XII B Roll no: 19 PROGRAM 1 Objective: Write a menu driven Python program using function to: a. Find the factorial of a number. b. Print first ‘n’ Prime numbers. c. To check if a number is a Palindrome or not. Concepts used: while loop, functions. Source code: while True: print("1. To find the factorial of a number") print("2. To print the first 'n' prime numbers") print("3. To check if a number is a palindrome or not") print("Enter 0 to exit") print() ch=int(input("Enter your choice :")) if ch==1: def factorial(): n=int(input("Enter a number :")) f=1 for i in range(1,n+1): f=f*i print("The factorial of ",n,"is",f) factorial() print() elif ch==2: def prime(): n=int(input("Enter a number :")) print("The prime numbers are : ") for i in range(2,n+1): if i==2: print(2) else: for j in range(2,i): if i%j==0: break else: print(i) prime() print() elif ch==3: def num_palindrome(): num = int(input("Enter a number: ")) rev = 0 temp = num while temp != 0: rem = temp % 10 rev = rev * 10 + rem temp = temp // 10 if num == rev: print(num, "is a palindrome") else: print(num, "is not a palindrome") num_palindrome() print() elif ch==0: print("Exiting the program now !") break Output: 1. To find the factorial of a number 2. To print the first 'n' prime numbers 3. To check if a number is a palindrome or not Enter 0 to exit Enter your choice :1 Enter a number :5 The factorial of 5 is 120 1. To find the factorial of a number 2. To print the first 'n' prime numbers 3. To check if a number is a palindrome or not Enter 0 to exit Enter your choice :2 Enter a number :10 The prime numbers are : 2 3 5 7 1. To find the factorial of a number 2. To print the first 'n' prime numbers 3. To check if a number is a palindrome or not Enter 0 to exit Enter your choice :3 Enter a number: 767 767 is a palindrome 1. To find the factorial of a number 2. To print the first 'n' prime numbers 3. To check if a number is a palindrome or not Enter 0 to exit Enter your choice :0 Exiting the program now ! PROGRAM 2 Objective: Write a menu driven program using function to: a. Check if a given string is a Palindrome. b. Count the number of alphabets, special characters, and digits in a string. c. Remove all vowels from a string. Concepts used: while loop, functions. Source code: while True: print("1. Check if a given string is a palindrome") print("2. Count the number of alphabets, special characters, and digits in a string") print("3. Remove all the vowels from a string") print("Enter 0 to exit") ch=int(input("Enter the choice:")) print() if ch==1: def str_palindrome(): str=input('Enter a string:') l=len(str) p=l-1 index=0 while index15000. d. Search by Employee Number and Modify the salary. Concepts used: while loop, functions, binary file. Source code: while True: import pickle f=open("Employee",'rb+') print("1. Append records to the file") print("2. Display all records from the file") print("3. Display details of employees with Salary >15000") print("4. Search by Employee Number and Modify the salary") print("Enter 0 to exit") print() choice=int(input("Enter choice [1,2,3, or 4]:")) if choice==1: def append_recs(): record=[] n=int(input("Enter the no of employees:")) for i in range(n): e_no=int(input("Enter the employee's number:")) name=input("Enter the employee's name:") des=input("Enter employee's designation:") salary=int(input("Enter the employee's salary:")) data=[e_no,name,des,salary] record.append(data) pickle.dump(record,f) print() print("Records Appended successfully") print() append_recs() elif choice==2: def display_recs(): data=pickle.load(f) for i in data: for j in i: print(j,end=' ') print() print() display_recs() elif choice==3: def employee_details(): data=pickle.load(f) for i in data: if i>15000: for j in i: print(j,end=' ') print() print() employee_details() elif choice==4: def modify_salary(): data=pickle.load(f) no=int(input("Enter number of employee whose salary has to be modified:")) for i in data: if i==no: salary=int(input("Enter the new salary of employee:")) i=salary break f.seek(0) pickle.dump(data,f) f.seek(0) new=pickle.load(f) print("The modified details:") for i in new: for j in i: print(j,end=' ') print() print() modify_salary() elif choice==0: print("Exiting the program now!") break Output: 1. Append records to the file 2. Display all records from the file 3. Display details of employees with Salary >15000 4. Search by Employee Number and Modify the salary Enter 0 to exit Enter choice [1,2,3, or 4]:1 Enter the no of employees:4 Enter the employee's number:526 Enter the employee's name:Sushant Enter employee's designation:Manager Enter the employee's salary:12500 Enter the employee's number:517 Enter the employee's name:Radhika Enter employee's designation:Supervisor Enter the employee's salary:14300 Enter the employee's number:512 Enter the employee's name:Hannah Enter employee's designation:CEO Enter the employee's salary:20000 Enter the employee's number:528 Enter the employee's name:Clifford Enter employee's designation:Manager Enter the employee's salary:18000 Records Appended successfully 1. Append records to the file 2. Display all records from the file 3. Display details of employees with Salary >15000 4. Search by Employee Number and Modify the salary Enter 0 to exit Enter choice [1,2,3, or 4]:2 526 Sushant Manager 12500 517 Radhika Supervisor 14300 512 Hannah CEO 20000 528 Clifford Manager 18000 1. Append records to the file 2. Display all records from the file 3. Display details of employees with Salary >15000 4. Search by Employee Number and Modify the salary Enter 0 to exit Enter choice [1,2,3, or 4]:3 512 Hannah CEO 20000 528 Clifford Manager 18000 1. Append records to the file 2. Display all records from the file 3. Display details of employees with Salary >15000 4. Search by Employee Number and Modify the salary Enter 0 to exit Enter choice [1,2,3, or 4]:4 Enter number of employee whose salary has to be modified:526 Enter the new salary of employee:14000 The modified details: 526 Sushant Manager 14000 517 Radhika Supervisor 14300 512 Hannah CEO 20000 528 Clifford Manager 18000 1. Append records to the file 2. Display all records from the file 3. Display details of employees with Salary >15000 4. Search by Employee Number and Modify the salary Enter 0 to exit Enter choice [1,2,3, or 4]:0 Exiting the program now! PROGRAM 9 Objective: The file ‘Book’ contains the following information : Book Number, Title of the Book, Cost. Write a menu-driven program in Python to perform the following tasks: a. Append records to the file. b. Display all records from the file. c. Search by Book Number and display details. d. Increase cost of all books by 2%. Concepts used: while loop, functions, binary file. Source code: while True: import pickle f=open("Book",'rb+') print("1. Append records to the file") print("2. Display all records from the file") print("3. Search by Book Number and display details") print("4. Increase cost of all books by 2%") print("Enter 0 to exit") print() choice=int(input("Enter choice [1,2,3, or 4]:")) if choice==1: def append_recs(): record=[] n=int(input("Enter the no of books:")) for i in range(1,n+1): Book_no=int(input("Enter the book number"+ " " + str(i) + " :")) Title=input("Enter the title of the book"+ " " + str(i) + " :") Cost=float(input("Enter the cost of the book"+ " " + str(i) + " :$")) data=[Book_no,Title,Cost] record.append(data) pickle.dump(record,f) print() print("Records Appended successfully") print() append_recs() elif choice==2: def display_recs(): data=pickle.load(f) for i in data: for j in i: print(j,end=' ') print() print() display_recs() elif choice==3: def book_display(): data=pickle.load(f) num=int(input("Enter the book number:")) for i in data: if i==num: for j in i: print(j,end=' ') print() print() book_display() elif choice==4: def modify_cost(): data=pickle.load(f) for i in data: modified_cost = i * 1.02 i = modified_cost f.seek(0) pickle.dump(data,f) f.seek(0) new = pickle.load(f) print("The modified details:") for i in new: for j in i: print(j, end=' ') print() print() modify_cost() elif choice==0: print("Exiting the program now!") break Output: 1. Append records to the file 2. Display all records from the file 3. Search by Book Number and display details 4. Increase cost of all books by 2% Enter 0 to exit Enter choice [1,2,3, or 4]:1 Enter the no of books:4 Enter the book number 1 :312 Enter the title of the book 1 :The Great Gatsby Enter the cost of the book 1 :$56 Enter the book number 2 :313 Enter the title of the book 2 :Harry Potter Enter the cost of the book 2 :$32 Enter the book number 3 :314 Enter the title of the book 3 :War and Peace Enter the cost of the book 3 :$45 Enter the book number 4 :315 Enter the title of the book 4 :The Old Man and the Sea Enter the cost of the book 4 :$22 Records Appended successfully 1. Append records to the file 2. Display all records from the file 3. Search by Book Number and display details 4. Increase cost of all books by 2% Enter 0 to exit Enter choice [1,2,3, or 4]:2 312 The Great Gatsby 56.0 313 Harry Potter 32.0 314 War and Peace 45.0 315 The Old Man and the Sea 22.0 1. Append records to the file 2. Display all records from the file 3. Search by Book Number and display details 4. Increase cost of all books by 2% Enter 0 to exit Enter choice [1,2,3, or 4]:3 Enter the book number:314 314 War and Peace 45.0 1. Append records to the file 2. Display all records from the file 3. Search by Book Number and display details 4. Increase cost of all books by 2% Enter 0 to exit Enter choice [1,2,3, or 4]:4 The modified details: 312 The Great Gatsby 57.120000000000005 313 Harry Potter 32.64 314 War and Peace 45.9 315 The Old Man and the Sea 22.44 1. Append records to the file 2. Display all records from the file 3. Search by Book Number and display details 4. Increase cost of all books by 2% Enter 0 to exit Enter choice [1,2,3, or 4]:0 Exiting the program now! PROGRAM 10 Objective: The file ‘Student’ contains the following information : Roll number, Name, and Marks. a. Append records to the file. b. Search for a given roll number and display the name, if not found display the appropriate message. c. Input a roll number and update the marks. Concepts used: while loop, functions, binary file. Source code: while True: import pickle f=open("Student",'rb+') print("1. Append records to the file") print("2. Search for a given roll number and display the name, if not found display appropriate message. ") print("3. Input a roll number and update the marks") print("Enter 0 to exit") print() choice=int(input("Enter choice [1,2, or 3]:")) if choice==1: def append_recs(): record=[] n=int(input("Enter the no of students:")) for i in range(1,n+1): Roll_no=int(input("Enter the roll number of student:")) Name=input("Enter the name of student:") Marks=int(input("Enter the marks of student:")) data=[Roll_no,Name,Marks] record.append(data) pickle.dump(record,f) print() print("Records Appended successfully") print() append_recs() elif choice==2: def display_name(): data=pickle.load(f) roll_no=int(input("Enter the roll number to search for:")) for i in data: if i==roll_no: print("The student with roll number",roll_no,"is",i) break else: print("Roll number not found!") print() display_name() elif choice==3: def modified_marks(): data=pickle.load(f) roll_no=int(input("Enter the roll number of student:")) marks=int(input("Enter the new marks of the student:")) for i in data: if i==roll_no: i=marks f.seek(0) pickle.dump(data,f) f.seek(0) new=pickle.load(f) print("The modified details:") for i in new: for j in i: print(j,end=' ') print() print() modified_marks() elif choice==0: print("Exiting the program now!") break Output: 1. Append records to the file 2. Search for a given roll number and display the name, if not found display the appropriate message. 3. Input a roll number and update the marks Enter 0 to exit Enter choice [1,2, or 3]:1 Enter the no of students:4 Enter the roll number of student:1 Enter the name of student:Gina Enter the marks of student:78 Enter the roll number of student:2 Enter the name of student:Glinda Enter the marks of student:89 Enter the roll number of student:3 Enter the name of student:Hannah Enter the marks of student:67 Enter the roll number of student:4 Enter the name of student:Ian Enter the marks of student:89 Records Appended successfully 1. Append records to the file 2. Search for a given roll number and display the name, if not found display appropriate message. 3. Input a roll number and update the marks Enter 0 to exit Enter choice [1,2, or 3]:2 Enter the roll number to search for:3 The student with roll number 3 is Hannah 1. Append records to the file 2. Search for a given roll number and display the name, if not found display appropriate message. 3. Input a roll number and update the marks Enter 0 to exit Enter choice [1,2, or 3]:3 Enter the roll number of student:3 Enter the new marks of the student:78 The modified details: 1 Gina 78 2 Glinda 89 3 Hannah 78 4 Ian 89 1. Append records to the file 2. Search for a given roll number and display the name, if not found display appropriate message. 3. Input a roll number and update the marks Enter 0 to exit Enter choice [1,2, or 3]:0 Exiting the program now! PROGRAM 11 Objective: Write a Menu driven program to: 1. Append to CSV File 2. Display from CSV File 3. Search and display by EmployeeNo File Name : Payroll.csv Fields : EmployeeNo, Employee Name, Salary Concepts used: while loop, functions, csv file. Source code: while True: import csv print("1.Append to a csv file") print("2.Display from csv file") print("3.Search and display by Employee Number") print("Enter 0 to exit") ch=int(input('Enter choice [1,2,or 3] :')) if ch==1: def append_csv(): Fields=['EmployeeNo','Employee Name','Salary'] rows=[] n=int(input("Enter the number of Employees:")) for i in range(1,n+1): EmployeeNo=int(input('Enter employee number:')) EmployeeName=input('Enter employee name:') Salary=int(input('Enter employee salary:')) record=[EmployeeNo,EmployeeName,Salary] rows.append(record) with open ('Payroll.csv','w+',newline='') as f: csv_w=csv.writer(f,delimiter=',') csv_w.writerow(Fields) for i in rows: csv_w.writerow(i) print('File appended') append_csv() elif ch==2: def display_csv(): f=open('Payroll.csv','r+') csvreader=csv.reader(f) for row in csvreader: print(row) f.close() display_csv() elif ch==3: def display_employee(): try: with open('Payroll.csv', 'r') as f: reader = csv.reader(f) employee_id = input('Enter employee number to search: ') for row in reader: if row == employee_id: print("Employee found:") print(row) break else: print("Employee not found.") except EOFError: print() display_employee() elif ch==0: print("Exiting the program now!") break Output: 1.Append to a csv file 2.Display from csv file 3.Search and display by Employee No Enter 0 to exit Enter choice [1,2,or 3] :1 Enter the number of Employees:4 Enter employee number:546 Enter employee name:Yasmin Enter employee salary:9700 Enter employee number:532 Enter employee name:Isabella Enter employee salary:13000 Enter employee number:555 Enter employee name:Daniel Enter employee salary:6700 Enter employee number:523 Enter employee name:Beth Enter employee salary:20000 File appended 1.Append to a csv file 2.Display from csv file 3.Search and display by Employee No Enter 0 to exit Enter choice [1,2,or 3] :2 ['EmployeeNo', 'Employee Name', 'Salary'] ['546', 'Yasmin', '9700'] ['532', 'Isabella', '13000'] ['555', 'Daniel', '6700'] ['523', 'Beth', '20000'] 1.Append to a csv file 2.Display from csv file 3.Search and display by Employee No Enter 0 to exit Enter choice [1,2,or 3] :3 Enter employee number to search: 555 Employee found: ['555', 'Daniel', '6700'] 1.Append to a csv file 2.Display from csv file 3.Search and display by Employee No Enter 0 to exit Enter choice [1,2,or 3] :0 Exiting the program now! PROGRAM 12 Objective: Write a Menu driven program to 1. Append to CSV File 2. Read from CSV File 3. Search and display by RollNo File Name : StRecords.CSV Fields : RollNo , Name , Stream, Marks Concepts used: while loop, functions, csv file. Source code: while True: import csv print("1.Append to a csv file") print("2.Display from csv file") print("3.Search and display by Roll Number") print("Enter 0 to exit") ch=int(input('Enter choice [1,2,or 3] :')) if ch==1: def append_csv(): Fields=['Roll No','Name','Stream','Marks'] rows=[] n=int(input("Enter the number of students:")) for i in range(1,n+1): RollNo=int(input('Enter the roll number of student:')) Name=input('Enter student name:') Stream=input('Enter the stream:') Marks=int(input('Enter student marks:')) record=[RollNo,Name,Stream,Marks] rows.append(record) with open ('StRecords.csv','w+',newline='') as f: csv_w=csv.writer(f,delimiter=',') csv_w.writerow(Fields) for i in rows: csv_w.writerow(i) print('File created') append_csv() elif ch==2: def display_csv(): f=open('StRecords.csv','r+') csvreader=csv.reader(f) for row in csvreader: print(row) f.close() display_csv() elif ch==3: def display_RollNo(): try: with open('StRecords.csv', 'r') as f: reader = csv.reader(f) roll_no = input('Enter roll number to search: ') for row in reader: if row == roll_no: print("Student found:") print(row) break else: print("Student not found.") except EOFError: print() display_RollNo() elif ch==0: print("Exiting the program now!") break Output: 1.Append to a csv file 2.Display from csv file 3.Search and display by Roll Number Enter 0 to exit Enter choice [1,2,or 3] :1 Enter the number of students:4 Enter the roll number of student:1 Enter student name:Gwendolyn Enter the stream:Science Enter student marks:74 Enter the roll number of student:2 Enter student name:Hailey Enter the stream:Science Enter student marks:89 Enter the roll number of student:3 Enter student name:Halloran Enter the stream:Commerce Enter student marks:94 Enter the roll number of student:4 Enter student name:Samantha Enter the stream:Humanities Enter student marks:88 File created 1.Append to a csv file 2.Display from csv file 3.Search and display by Roll Number Enter 0 to exit Enter choice [1,2,or 3] :2 ['Roll No', 'Name', 'Stream', 'Marks'] ['1', 'Gwendolyn', 'Science', '74'] ['2', 'Hailey', 'Science', '89'] ['3', 'Halloran', 'Commerce', '94'] ['4', 'Samantha', 'Humanities', '88'] 1.Append to a csv file 2.Display from csv file 3.Search and display by Roll Number Enter 0 to exit Enter choice [1,2,or 3] :3 Enter roll number to search: 3 Student found: ['3', 'Halloran', 'Commerce', '94'] 1.Append to a csv file 2.Display from csv file 3.Search and display by Roll Number Enter 0 to exit Enter choice [1,2,or 3] :0 Exiting the program now! PROGRAM 13 Objective: Write a menu driven program to implement a stack for the book details BookNo – String Bookname – String Cost – Float Concepts used: while loop, functions, stack. Source code: while True: print("1. PUSH book details") print("2. POP topmost book") print("3. Display stack of all books") print("Enter zero to exit") choice=int(input("Enter choice [1,2, or 3]:")) print() if choice==1: S=[] n = int(input("Enter the number of books:")) for i in range(n): BookNo=input("Enter the number of the book:") Bookname=input("Enter the name of the book:") Cost=float(input("Enter the cost of the book: $")) Det=(BookNo,Bookname,Cost) S.append(Det) print() elif choice==2: if S==[]: print("THE STACK IS EMPTY: cannot delete topmost element") else: S.pop() print("Topmost element deleted") print() elif choice==3: print("BookNo\t","BookName","\tCost") for book in range(len(S) - 1, -1, -1): print(S[book]) print() elif choice==0: print("Exiting the program now!") break Output: 1. PUSH book details 2. POP topmost book 3. Display stack of all books Enter zero to exit Enter choice [1,2, or 3]:1 Enter the number of books:4 Enter the number of the book:111 Enter the name of the book:Percy Jackson Enter the cost of the book: $34 Enter the number of the book:112 Enter the name of the book:Jane Eyre Enter the cost of the book: $24 Enter the number of the book:113 Enter the name of the book:Hunger Games Enter the cost of the book: $54 Enter the number of the book:114 Enter the name of the book:Oliver Twist Enter the cost of the book: $22 1. PUSH book details 2. POP topmost book 3. Display stack of all books Enter zero to exit Enter choice [1,2, or 3]:3 BookNo BookName Cost ('114', 'Oliver Twist', 22.0) ('113', 'Hunger Games', 54.0) ('112', 'Jane Eyre', 24.0) ('111', 'Percy Jackson', 34.0) 1. PUSH book details 2. POP topmost book 3. Display stack of all books Enter zero to exit Enter choice [1,2, or 3]:2 Topmost element deleted 1. PUSH book details 2. POP topmost book 3. Display stack of all books Enter zero to exit Enter choice [1,2, or 3]:3 BookNo BookName Cost ('113', 'Hunger Games', 54.0) ('112', 'Jane Eyre', 24.0) ('111', 'Percy Jackson', 34.0) 1. PUSH book details 2. POP topmost book 3. Display stack of all books Enter zero to exit Enter choice [1,2, or 3]:0 PROGRAM 14 Objective: Write a menu driven program to add,delete and display records of an employee using List. Concepts used: while loop, functions, stack. Source code: while True: print("1. PUSH employee records") print("2. POP topmost employee record") print("3. Display stack of all employee records") print("Enter zero to exit") choice=int(input("Enter choice [1,2, or 3]:")) print() if choice==1: S=[] n = int(input("Enter the number of Employees:")) for i in range(n): EmployeeNo=input("Enter the number of employee:") EmployeeName=input("Enter the name of employee:") Des=input("Enter the designation of employee:") Salary=int(input("Enter salary of employee: $")) Det=[EmployeeNo,EmployeeName,Des,Salary] S.append(Det) print() elif choice==2: if S==[]: print("THE STACK IS EMPTY: cannot delete topmost element") else: S.pop() print("Topmost element deleted") print() elif choice==3: print("EmployeeNo","EmployeeName","Designation","Salary") for i in range(len(S) - 1, -1, -1): print(S[i]) print() elif choice==0: print("Exiting the program now!") break Output: 1. PUSH employee records 2. POP topmost employee record 3. Display stack of all employee records Enter zero to exit Enter choice [1,2, or 3]:1 Enter the number of Employees:4 Enter the number of employee:230 Enter the name of employee:Elaina Enter the designation of employee:Manager Enter salary of employee: $12000 Enter the number of employee:231 Enter the name of employee:Ginny Enter the designation of employee:Admin Enter salary of employee: $11300 Enter the number of employee:210 Enter the name of employee:Rachel Enter the designation of employee:HR Enter salary of employee: $12200 Enter the number of employee:221 Enter the name of employee:Mark Enter the designation of employee:Supervisor Enter salary of employee: $13300 1. PUSH employee records 2. POP topmost employee record 3. Display stack of all employee records Enter zero to exit Enter choice [1,2, or 3]:3 EmployeeNo EmployeeName Designation Salary ['221', 'Mark', 'Supervisor', 13300] ['210', 'Rachel', 'HR', 12200] ['231', 'Ginny', 'Admin', 11300] ['230', 'Elaina', 'Manager', 12000] 1. PUSH employee records 2. POP topmost employee record 3. Display stack of all employee records Enter zero to exit Enter choice [1,2, or 3]:2 Topmost element deleted 1. PUSH employee records 2. POP topmost employee record 3. Display stack of all employee records Enter zero to exit Enter choice [1,2, or 3]:3 EmployeeNo EmployeeName Designation Salary ['210', 'Rachel', 'HR', 12200] ['231', 'Ginny', 'Admin', 11300] ['230', 'Elaina', 'Manager', 12000] 1. PUSH employee records 2. POP topmost employee record 3. Display stack of all employee records Enter zero to exit Enter choice [1,2, or 3]:0 Exiting the program now! PROGRAM 15 Objective: Write a menu driven program using stack a)to display vowels and consonants in the given word b) to reverse a word using stack Concepts used: while loop, functions, stack. Source code: while True: print("1. To display vowels and consonants in the given word") print("2. To reverse a word using stack") print("Enter 0 to exit") print() choice=int(input("Enter choice [1 or 2]:")) print() if choice==1: def display(): word=input("Enter a word:") vowel='aeiouAEIOU' stack = [] vowels = [] consonants = [] for i in word: if i.isalpha(): if i in vowel: vowels.append(i) else: consonants.append(i) print("Vowels in the word: ", vowels) print("Consonants in the word: ", consonants) print() display() elif choice==2: def reverse(): stack = [] word=input("Enter a word:") for i in word: stack.append(i) reversed_word = '' while stack: reversed_word += stack.pop() print("The reversed word is:",reversed_word) print() reverse() elif choice==0: print("Exiting the program now!") break Output: 1. To display vowels and consonants in the given word 2. To reverse a word using stack Enter 0 to exit Enter choice [1 or 2]:1 Enter a word:Pineapple Vowels in the word: ['i', 'e', 'a', 'e'] Consonants in the word: ['P', 'n', 'p', 'p', 'l'] 1. To display vowels and consonants in the given word 2. To reverse a word using stack Enter 0 to exit Enter choice [1 or 2]:2 Enter a word:Magnanimous The reversed word is: suominangaM 1. To display vowels and consonants in the given word 2. To reverse a word using stack Enter 0 to exit Enter choice [1 or 2]:0 Exiting the program now! SQL – 1. To create a database ELECTRICITY with table EBILL, and write queries and generate output of the following: >CREATE DATABASE ELECTRICITY; >USE ELECTRICITY; >CREATE TABLE EBILL(RR_NO CHAR(3), CON_NAME VARCHAR(20), DATE_BILL DATE, UNIT INTEGER); >INSERT INTO EBILL VALUES(‘A11’,’Jothika’,’2020-10-02’,224); >INSERT INTO EBILL VALUES(‘A12’,’Titas’,’2020-09-12’,212); >INSERT INTO EBILL VALUES(‘A13’,’Ankan’,’2020-09-24’,232); >INSERT INTO EBILL VALUES(‘A14’,’Deepak’,’2020-10-01’,242); >INSERT INTO EBILL VALUES(‘A15’,’Archana’,’2020-10-04’,244); >SELECT * FROM EBILL; 1. Add new field to the table-Bill_amt of datatype decimal(10,2). >ALTER TABLE EBILL ADD BILL_AMT DECIMAL(10,2); >DESC EBILL; 2. Compute the bill amount for each customer as MinAmt + 4.50 per unit (MinAmt = 50) > UPDATE EBILL SET BILL_AMT=50+4.50*UNIT; > SELECT * FROM EBILL; 3. Display Customer name and Bill Amount where Bill Amount > 1000. > SELECT CON_NAME,BILL_AMT FROM EBILL WHERE BILL_AMT>1000; 4. Display the min, max, sum and average of Unit. > SELECT MIN(UNIT),MAX(UNIT),SUM(UNIT),AVG(UNIT) FROM EBILL; 5. Display details of Customers whose name starts with ‘A’. > SELECT * FROM EBILL WHERE CON_NAME LIKE "A_%"; 6. Display Bills generated in the month of October. > SELECT * FROM EBILL WHERE DATE_BILL>='2020-10-01'; 7. List all the bills generated in ascending order of Bill Date. > SELECT * FROM EBILL ORDER BY BILL_AMT; SQL - 2. To create a database STORE in MySQL with tables PRODUCTS and SUPPLIERS & write queries and generate output of the following:- Table 1: PRODUCTS Table 2: SUPPLIERS >CREATE DATABASE STORE; >USE STORE; > CREATE TABLE PRODUCTS(PID INTEGER, PNAME VARCHAR(20), QTY INTEGER, PRICE INTEGER, COMPANY VARCHAR(20), SUPCODE CHAR(3)); > INSERT INTO PRODUCTS VALUES(101, 'Digital Camera 14 X', 120, 12000, 'Renix', 'S01'); > INSERT INTO PRODUCTS VALUES(102, 'Digital Pad 11i', 100, 22000, 'Digi Pop', 'S02'); > INSERT INTO PRODUCTS VALUES(104, 'Pen Drive 16 GB', 500, 1100, 'Storeking', 'S01'); > INSERT INTO PRODUCTS VALUES(105, 'Car GPS System', 60, 12000, 'Moveon', 'S03'); > INSERT INTO PRODUCTS VALUES(106, 'LED Screen', 70, 28000, 'Dispexperts', 'S02'); > SELECT * FROM PRODUCTS; > CREATE TABLE SUPPLIERS(SUPCODE CHAR(3), SNAME VARCHAR(20), CITY VARCHAR(15)); > INSERT INTO SUPPLIERS VALUES('S01', 'GET ALL INC', 'KOLKATA'); > INSERT INTO SUPPLIERS VALUES('S02', 'DIGI BUSY GROUP', 'CHENNAI'); > INSERT INTO SUPPLIERS VALUES('S03', 'EASY MARKET CORP', 'DELHI'); > SELECT * FROM SUPPLIERS; 1. Change name of Supplier ‘S01’ from ‘Get All Inc’ to ‘Get Digital’. > UPDATE SUPPLIERS SET SNAME='GET DIGITAL' WHERE SUPCODE='S01'; > SELECT * FROM SUPPLIERS; 2. Display all records of PRODUCTS in ascending order of Product Name > SELECT * FROM PRODUCTS ORDER BY PNAME; 3. Display Product Name, Price of all products in the price range 10000 to 150000 (inclusive) > SELECT PNAME, PRICE FROM PRODUCTS WHERE PRICE BETWEEN 10000 AND 150000; 4. Display the Product Name, Price & Quantity of all products with Quantity more than 100. > SELECT PNAME, PRICE, QTY FROM PRODUCTS WHERE QTY>100; 5. Display names of Suppliers from Delhi and Chennai. > SELECT SNAME FROM SUPPLIERS WHERE CITY='DELHI' OR CITY='CHENNAI'; 6. Display names of Product Name, Supplier Name, City from Kolkota. > SELECT PNAME, SNAME, CITY FROM PRODUCTS, SUPPLIERS WHERE PRODUCTS.SUPCODE=SUPPLIERS.SUPCODE AND SUPPLIERS.CITY='KOLKATA'; 7. Display Product ID, Product Name, Supplier Name and Price * Quantity of all products from Supplier ‘S02’. > SELECT PID, PNAME, SNAME, PRICE * QTY FROM PRODUCTS, SUPPLIERS WHERE PRODUCTS.SUPCODE = SUPPLIERS.SUPCODE AND SUPPLIERS.SUPCODE = 'S02'; 8. Display the number of Products supplied by each Supplier. > SELECT SUPCODE, COUNT(PNAME) AS ProductCount FROM PRODUCTS GROUP BY SUPCODE; SQL - 3. Create a Database LIBRARY and execute the SQL Commands to generate the output for each of the following statements. > CREATE DATABASE LIBRARY; > USE LIBRARY; > CREATE TABLE BOOKS(book_id char(5), book_name varchar(20), author_name varchar(20), publisher varchar(20), price integer, type varchar(20), qty integer); > INSERT INTO BOOKS VALUES('C0001', 'FAST COOK', 'LATA KAPOOR', 'EPB', 405, 'COOKERY', 5); > INSERT INTO BOOKS VALUES('F0001', 'THE TEARS', 'WILLIAM HOPKINS', 'FIRST PUBL', 650, 'FICTION', 20); > INSERT INTO BOOKS VALUES('F0002', 'THUNDERBOLTS', 'ANNA ROBERTS', 'FIRST PUBL', 750, 'FICTION', 50); > INSERT INTO BOOKS VALUES('T0001', 'MY FIRST C++', 'BRIAN & BROOKE', 'EPB', 400, 'TEXTBOOK', 10); > INSERT INTO BOOKS VALUES('T0002', 'C++ BRAINWORKS', 'A W ROSSAINE', 'TDH', 350, 'TEXTBOOK', 15); > SELECT * FROM BOOKS; > CREATE TABLE ISSUED(book_id char(5), quantity_issued integer); > INSERT INTO ISSUED VALUES('C0001',5); > INSERT INTO ISSUED VALUES('F0001',2); > INSERT INTO ISSUED VALUES('T0001',4); > SELECT * FROM ISSUED; 1. To show Book_Name , Author_name and Price of books of First Publ. publishers. > SELECT book_name, author_name, price FROM BOOKS WHERE publisher='FIRST PUBL'; 2. To list the names from books of ‘TEXTBOOK’ type. > SELECT book_name FROM BOOKS WHERE type='TEXTBOOK'; 3. To display the names and prices from books in ascending order of price. > SELECT book_name, price FROM BOOKS ORDER BY price; 4. To increase the price of all books of EPB Publishers by 50. > UPDATE BOOKS SET price=price+50 WHERE publisher='EPB'; > SELECT * FROM BOOKS; 5. To display the Book_Id , Book_Name and Quantity_Issued for all books which have been issued. > SELECT book_id, book_name, quantity_issued FROM BOOKS NATURAL JOIN ISSUED; SQL - 4. To create a database COMPANY with table EMPLOYEE in MySQL & create an API using Python Connectivity. Write a menu-driven program to ACCEPT new employee details and display all records. DISPLAY employee details by employee number; display appropriate message if employee number not matched. UPDATE the Salary by employee number. DELETE Record by employee number. Source Code: import mysql.connector mydb = mysql.connector.connect(host='localhost',user='root',password='12345', database='COMPANY') mycursor = mydb.cursor() while True: print() print("1. TO CREATE TABLE") print("2. TO STORE RECORDS OF EMPLOYEE AND DISPLAY THE TABLE") print("3. TO SEARCH FOR AN EMPLOYEE") print("4. TO UPDATE THE SALARY OF THE EMPLOYEE") print("5. TO DELETE THE EMPLOYEE RECORD") print("ENTER 0 TO EXIT") print() ch = int(input("ENTER CHOICE: ")) print() if ch == 0: print("EXITING THE PROGRAM NOW") break elif ch == 1: mycursor.execute("CREATE TABLE IF NOT EXISTS EMPLOYEE(EMPNO int, NAME varchar(20), DEPT varchar(20), SALARY int)") print("TABLE HAS BEEN CREATED") mydb.commit() elif ch == 2: n = int(input("ENTER TOTAL NUMBER OF EMPLOYEES: ")) print() for i in range(n): eno = int(input("ENTER EMPLOYEE NUMBER: ")) name = input("ENTER EMPLOYEE NAME: ") dept = input("ENTER EMPLOYEE DEPARTMENT: ") sal = int(input("ENTER SALARY: ")) print() mycursor.execute("INSERT INTO EMPLOYEE (EMPNO, NAME, DEPT, SALARY) VALUES (%s, %s, %s, %s)", (eno, name, dept, sal)) print("RECORD HAS BEEN INSERTED") print() mydb.commit() mycursor.execute("SELECT * FROM EMPLOYEE") data = mycursor.fetchall() for i in data: for j in i: print(j, end=" ") print() elif ch == 3: eno = int(input("ENTER EMPLOYEE NUMBER OF THE EMPLOYEE TO BE FOUND: ")) print() mycursor.execute("SELECT * FROM EMPLOYEE WHERE EMPNO = %s", (eno,)) data = mycursor.fetchall() if not data: print("EMPLOYEE NOT FOUND") else: print("EMPLOYEE FOUND") for i in data: for j in i: print(j, end=" ") print() elif ch == 4: eno = int(input("ENTER EMPLOYEE NUMBER OF THE EMPLOYEE WHOSE SALARY HAS TO BE UPDATED: ")) print() sal = int(input("ENTER THE UPDATED SALARY: ")) print() mycursor.execute("UPDATE EMPLOYEE SET SALARY = %s WHERE EMPNO = %s", (sal, eno)) print("SALARY HAS BEEN UPDATED") print() print("UPDATED DETAILS") mycursor.execute("SELECT * FROM EMPLOYEE") data = mycursor.fetchall() for i in data: for j in i: print(j, end=" ") print() elif ch == 5: ename = input("ENTER EMPLOYEE NAME OF THE EMPLOYEE WHOSE RECORD HAS TO BE DELETED: ") print() mycursor.execute("DELETE FROM EMPLOYEE2 WHERE NAME = %s", (ename,)) mydb.commit() print("EMPLOYEE RECORD HAS BEEN DELETED") print() print("DETAILS AFTER DELETION") print() mycursor.execute("SELECT * FROM EMPLOYEE") data = mycursor.fetchall() for i in data: for j in i: print(j, end=" ") print() mydb.commit() elif ch==0: print('Exiting the program now!') else: print("INVALID CHOICE. PLEASE TRY AGAIN.") Output: 1. TO CREATE TABLE 2. TO STORE RECORDS OF EMPLOYEE AND DISPLAY THE TABLE 3. TO SEARCH FOR AN EMPLOYEE 4. TO UPDATE THE SALARY OF THE EMPLOYEE 5. TO DELETE THE EMPLOYEE RECORD ENTER 0 TO EXIT ENTER CHOICE: 1 TABLE HAS BEEN CREATED 1. TO CREATE TABLE 2. TO STORE RECORDS OF EMPLOYEE AND DISPLAY THE TABLE 3. TO SEARCH FOR AN EMPLOYEE 4. TO UPDATE THE SALARY OF THE EMPLOYEE 5. TO DELETE THE EMPLOYEE RECORD ENTER 0 TO EXIT ENTER CHOICE: 2 ENTER TOTAL NUMBER OF EMPLOYEES: 4 ENTER EMPLOYEE NUMBER: 1 ENTER EMPLOYEE NAME: AMIT ENTER EMPLOYEE DEPARTMENT: SALES ENTER SALARY: 20000 RECORD HAS BEEN INSERTED ENTER EMPLOYEE NUMBER: 2 ENTER EMPLOYEE NAME: NITIN ENTER EMPLOYEE DEPARTMENT: IT ENTER SALARY: 28000 RECORD HAS BEEN INSERTED ENTER EMPLOYEE NUMBER: 3 ENTER EMPLOYEE NAME: JAMES ENTER EMPLOYEE DEPARTMENT: ACCOUNTS ENTER SALARY: 16000 RECORD HAS BEEN INSERTED ENTER EMPLOYEE NUMBER: 4 ENTER EMPLOYEE NAME: ABEL ENTER EMPLOYEE DEPARTMENT: IT ENTER SALARY: 32000 RECORD HAS BEEN INSERTED 1 AMIT SALES 20000 2 NITIN IT 28000 3 JAMES ACCOUNTS 16000 4 ABEL IT 32000 1. TO CREATE TABLE 2. TO STORE RECORDS OF EMPLOYEE AND DISPLAY THE TABLE 3. TO SEARCH FOR AN EMPLOYEE 4. TO UPDATE THE SALARY OF THE EMPLOYEE 5. TO DELETE THE EMPLOYEE RECORD ENTER 0 TO EXIT ENTER CHOICE: 3 ENTER EMPLOYEE NUMBER OF THE EMPLOYEE TO BE FOUND: 3 EMPLOYEE FOUND 3 JAMES ACCOUNTS 16000 1. TO CREATE TABLE 2. TO STORE RECORDS OF EMPLOYEE AND DISPLAY THE TABLE 3. TO SEARCH FOR AN EMPLOYEE 4. TO UPDATE THE SALARY OF THE EMPLOYEE 5. TO DELETE THE EMPLOYEE RECORD ENTER 0 TO EXIT ENTER CHOICE: 3 ENTER EMPLOYEE NUMBER OF THE EMPLOYEE TO BE FOUND: 66 EMPLOYEE NOT FOUND 1. TO CREATE TABLE 2. TO STORE RECORDS OF EMPLOYEE AND DISPLAY THE TABLE 3. TO SEARCH FOR AN EMPLOYEE 4. TO UPDATE THE SALARY OF THE EMPLOYEE 5. TO DELETE THE EMPLOYEE RECORD ENTER 0 TO EXIT ENTER CHOICE: 4 ENTER EMPLOYEE NUMBER OF THE EMPLOYEE WHOSE SALARY HAS TO BE UPDATED: 3 ENTER THE UPDATED SALARY: 19000 SALARY HAS BEEN UPDATED UPDATED DETAILS 1 AMIT SALES 20000 2 NITIN IT 28000 3 JAMES ACCOUNTS 19000 4 ABEL IT 32000 1. TO CREATE TABLE 2. TO STORE RECORDS OF EMPLOYEE AND DISPLAY THE TABLE 3. TO SEARCH FOR AN EMPLOYEE 4. TO UPDATE THE SALARY OF THE EMPLOYEE 5. TO DELETE THE EMPLOYEE RECORD ENTER 0 TO EXIT ENTER CHOICE: 5 ENTER EMPLOYEE NAME OF THE EMPLOYEE WHOSE RECORD HAS TO BE DELETED: ABEL EMPLOYEE RECORD HAS BEEN DELETED DETAILS AFTER DELETION 1 AMIT SALES 20000 2 NITIN IT 28000 3 JAMES ACCOUNTS 19000 1. TO CREATE TABLE 2. TO STORE RECORDS OF EMPLOYEE AND DISPLAY THE TABLE 3. TO SEARCH FOR AN EMPLOYEE 4. TO UPDATE THE SALARY OF THE EMPLOYEE 5. TO DELETE THE EMPLOYEE RECORD ENTER 0 TO EXIT ENTER CHOICE: 0 EXITING THE PROGRAM NOW SQL - 5. To create a database ASSIGNMENT with table STUDENT in MySQL & create an API using Python Connectivity. Write the menu-driven program to : ADD New Records DISPLAY BY Status of Assignment Search by Roll No and UPDATE Status of Assignment Search by Roll No and DELETE Student Record DISPLAY ALL Records Source Code: import mysql.connector mydb = mysql.connector.connect(host='localhost',user='root',password='12345',database ='ASSIGNMENT') mycursor = mydb.cursor() while True: print() print("1. TO CREATE TABLE AND ADD NEW RECORDS") print("2. TO DISPLAY BY STATUS OF ASSIGNMENT") print("3. TO SEARCH BY ROLLNO AND UPDATE STATUS OF ASSIGNMENT") print("4. TO SEARCH BY ROLLNO AND DELETE STUDENT RECORD") print("5. TO DISPLAY ALL DETAILS") print("ENTER 0 TO EXIT") print() ch = int(input("ENTER CHOICE: ")) print() if ch == 0: print("EXITING THE PROGRAM NOW") break elif ch == 1: mycursor.execute("CREATE TABLE IF NOT EXISTS STUDENT (ROLLNO int, NAME varchar(20), PERCENTAGE float, SECTION char(1), ASSIGNMENT varchar(20))") print("TABLE HAS BEEN CREATED") mydb.commit() n = int(input("ENTER TOTAL NUMBER OF STUDENTS: ")) print() for i in range(n): ROLLNO = int(input("ENTER ROLL NUMBER: ")) NAME = input("ENTER STUDENT NAME: ") PERCENTAGE = float(input("ENTER ASSIGNMENT PERCENTAGE: ")) SECTION = input("ENTER SECTION OF STUDENT: ") ASSIGNMENT = input("ENTER ASSIGNMENT DETAILS: ") print() mycursor.execute("INSERT INTO STUDENT (ROLLNO, NAME, PERCENTAGE, SECTION, ASSIGNMENT) VALUES (%s, %s, %s, %s, %s)",(ROLLNO, NAME, PERCENTAGE, SECTION, ASSIGNMENT)) print("RECORD HAS BEEN INSERTED") print() mydb.commit() elif ch == 2: ASSIGNMENT = input("ENTER ASSIGNMENT STATUS TO SEARCH: ") print() mycursor.execute("SELECT * FROM STUDENT WHERE ASSIGNMENT = %s", (ASSIGNMENT,)) data = mycursor.fetchall() if not data: print("NO STUDENTS FOUND WITH ASSIGNMENT STATUS", ASSIGNMENT) else: print("STUDENTS WITH ASSIGNMENT STATUS", ASSIGNMENT) for row in data: print(row, row, row, row, row) print() elif ch == 3: ROLLNO = int(input("ENTER ROLL NUMBER OF THE STUDENT WHOSE ASSIGNMENT STATUS HAS TO BE UPDATED: ")) print() ASSIGNMENT = input("ENTER THE UPDATED STATUS OF ASSIGNMENT: ") print() mycursor.execute("UPDATE STUDENT SET ASSIGNMENT = %s WHERE ROLLNO = %s", (ASSIGNMENT, ROLLNO)) mydb.commit() print("STATUS HAS BEEN UPDATED") print() elif ch == 4: ROLLNO = int(input("ENTER ROLL NUMBER OF THE STUDENT TO DELETE: ")) print() mycursor.execute("DELETE FROM STUDENT WHERE ROLLNO = %s", (ROLLNO,)) mydb.commit() print("STUDENT RECORD DELETED") print() elif ch == 5: mycursor.execute("SELECT * FROM STUDENT") data = mycursor.fetchall() if not data: print("NO STUDENT RECORDS FOUND") else: for row in data: print(row, row, row, row, row) print() elif ch==0: print('Exiting the program now!') Output: 1. TO CREATE TABLE AND ADD NEW RECORDS 2. TO DISPLAY BY STATUS OF ASSIGNMENT 3. TO SEARCH BY ROLLNO AND UPDATE STATUS OF ASSIGNMENT 4. TO SEARCH BY ROLLNO AND DELETE STUDENT RECORD 5. TO DISPLAY ALL DETAILS ENTER 0 TO EXIT ENTER CHOICE: 1 TABLE HAS BEEN CREATED ENTER TOTAL NUMBER OF STUDENTS: 5 ENTER ROLL NUMBER: 103 ENTER STUDENT NAME: RUHANI ENTER ASSIGNMENT PERCENTAGE: 76.8 ENTER SECTION OF STUDENT: A ENTER ASSIGNMENT DETAILS: PENDING RECORD HAS BEEN INSERTED ENTER ROLL NUMBER: 104 ENTER STUDENT NAME: GEORGE ENTER ASSIGNMENT PERCENTAGE: 71.2 ENTER SECTION OF STUDENT: A ENTER ASSIGNMENT DETAILS: SUBMITTED RECORD HAS BEEN INSERTED ENTER ROLL NUMBER: 105 ENTER STUDENT NAME: SIMRAN ENTER ASSIGNMENT PERCENTAGE: 81.2 ENTER SECTION OF STUDENT: B ENTER ASSIGNMENT DETAILS: EVALUATED RECORD HAS BEEN INSERTED ENTER ROLL NUMBER: 107 ENTER STUDENT NAME: AHAMED ENTER ASSIGNMENT PERCENTAGE: 61.2 ENTER SECTION OF STUDENT: C ENTER ASSIGNMENT DETAILS: PENDING RECORD HAS BEEN INSERTED ENTER ROLL NUMBER: 108 ENTER STUDENT NAME: RAUNAK ENTER ASSIGNMENT PERCENTAGE: 32.5 ENTER SECTION OF STUDENT: B ENTER ASSIGNMENT DETAILS: SUBMITTED RECORD HAS BEEN INSERTED 1. TO CREATE TABLE AND ADD NEW RECORDS 2. TO DISPLAY BY STATUS OF ASSIGNMENT 3. TO SEARCH BY ROLLNO AND UPDATE STATUS OF ASSIGNMENT 4. TO SEARCH BY ROLLNO AND DELETE STUDENT RECORD 5. TO DISPLAY ALL DETAILS ENTER 0 TO EXIT ENTER CHOICE: 2 ENTER ASSIGNMENT STATUS TO SEARCH: SUBMITTED STUDENTS WITH ASSIGNMENT STATUS SUBMITTED 104 NAME: GEORGE 71.2 A SUBMITTED 108 NAME: RAUNAK 32.5 B SUBMITTED 1. TO CREATE TABLE AND ADD NEW RECORDS 2. TO DISPLAY BY STATUS OF ASSIGNMENT 3. TO SEARCH BY ROLLNO AND UPDATE STATUS OF ASSIGNMENT 4. TO SEARCH BY ROLLNO AND DELETE STUDENT RECORD 5. TO DISPLAY ALL DETAILS ENTER 0 TO EXIT ENTER CHOICE: 3 ENTER ROLL NUMBER OF THE STUDENT WHOSE ASSIGNMENT STATUS HAS TO BE UPDATED: 108 ENTER THE UPDATED STATUS OF ASSIGNMENT: EVALUATED STATUS HAS BEEN UPDATED 1. TO CREATE TABLE AND ADD NEW RECORDS 2. TO DISPLAY BY STATUS OF ASSIGNMENT 3. TO SEARCH BY ROLLNO AND UPDATE STATUS OF ASSIGNMENT 4. TO SEARCH BY ROLLNO AND DELETE STUDENT RECORD 5. TO DISPLAY ALL DETAILS ENTER 0 TO EXIT ENTER CHOICE: 4 ENTER ROLL NUMBER OF THE STUDENT TO DELETE: 107 STUDENT RECORD DELETED 1. TO CREATE TABLE AND ADD NEW RECORDS 2. TO DISPLAY BY STATUS OF ASSIGNMENT 3. TO SEARCH BY ROLLNO AND UPDATE STATUS OF ASSIGNMENT 4. TO SEARCH BY ROLLNO AND DELETE STUDENT RECORD 5. TO DISPLAY ALL DETAILS ENTER 0 TO EXIT ENTER CHOICE: 5 103 RUHANI 76.8 A PENDING 104 GEORGE 71.2 A SUBMITTED 105 SIMRAN 81.2 B EVALUATED 108 RAUNAK 32.5 B EVALUATED 1. TO CREATE TABLE AND ADD NEW RECORDS 2. TO DISPLAY BY STATUS OF ASSIGNMENT 3. TO SEARCH BY ROLLNO AND UPDATE STATUS OF ASSIGNMENT 4. TO SEARCH BY ROLLNO AND DELETE STUDENT RECORD 5. TO DISPLAY ALL DETAILS ENTER 0 TO EXIT ENTER CHOICE: 0 EXITING THE PROGRAM NOW SQL – 6. Create a table CAR with the following details. Design a menu driven API using Python Connectivity to: ACCEPT new employee details and DISPLAY all records. DISPLAY car details as per user input. Also display appropriate message if car number is not matched. UPDATE the Charge by car number DELETE Record by car number. Source code: import mysql.connector mydb = mysql.connector.connect(host='localhost',user='root',password='12345',database ='PRACTICAL') mycursor = mydb.cursor() while True: print() print("1. TO ACCEPT NEW CAR DETAILS AND DISPLAY ALL RECORDS") print("2. TO DISPLAY DETAILS BY CAR NUMBER") print("3. TO UPDATE THE CHARGE BY CAR NUMBER") print("4. TO DELETE RECORD BY CAR NUMBER") print("ENTER 0 TO EXIT") print() ch = int(input("ENTER CHOICE: ")) print() if ch == 0: print("EXITING THE PROGRAM NOW") break elif ch == 1: mycursor.execute("CREATE TABLE IF NOT EXISTS CAR (CCODE integer, CNAME varchar(20), COMPANY varchar(20), COLOUR varchar(20), CAPACITY integer, CHARGE integer)") print("TABLE HAS BEEN CREATED") mydb.commit() print() n = int(input("ENTER TOTAL NUMBER OF CARS: ")) print() for i in range(n): CCODE = int(input("ENTER CAR CODE/NUMBER: ")) CNAME = input("ENTER CAR NAME: ") COMPANY = input("ENTER CAR COMPANY: ") COLOUR = input("ENTER COLOUR OF CAR: ") CAPACITY = int(input("ENTER CAR CAPACITY: ")) CHARGE = int(input("ENTER CAR CHARGE: ")) print() mycursor.execute("INSERT INTO CAR (CCODE, CNAME, COMPANY, COLOUR, CAPACITY, CHARGE) VALUES (%s, %s, %s, %s, %s, %s)",(CCODE, CNAME, COMPANY, COLOUR, CAPACITY, CHARGE)) print("RECORD HAS BEEN INSERTED") print() mycursor.execute("SELECT * FROM CAR") data = mycursor.fetchall() if not data: print("NO CAR RECORDS FOUND") else: for row in data: print(str(row)+"\t"+row+"\t"+row+"\t"+row+"\t"+str(row)+"\t"+s tr(row)) print() elif ch == 2: CCODE = int(input("ENTER CAR NUMBER: ")) print() mycursor.execute("SELECT * FROM CAR WHERE CCODE = %s", (CCODE,)) data = mycursor.fetchall() if not data: print("NO CARS FOUND WITH CAR NUMBER", CCODE) else: print("CARS WITH CAR NUMBER", CCODE) for row in data: print(str(row)+"\t"+row+"\t"+row+"\t"+row+"\t"+str(row)+"\t"+s tr(row)) print() elif ch == 3: CCODE = int(input("ENTER CAR NUMBER: ")) print() CHARGE = input("ENTER THE UPDATED CHARGE OF CAR: ") print() mycursor.execute("UPDATE CAR SET CHARGE = %s WHERE CCODE = %s", (CHARGE, CCODE)) mydb.commit() print("CHARGE HAS BEEN UPDATED") print() mycursor.execute("SELECT * FROM CAR WHERE CCODE = %s", (CCODE,)) data = mycursor.fetchall() if not data: print("NO CARS FOUND WITH CAR NUMBER", CCODE) else: print("CARS WITH CAR NUMBER", CCODE) for row in data: print(str(row)+"\t"+row+"\t"+row+"\t"+row+"\t"+str(row)+"\t"+s tr(row)) print() print("\nUPDATED CAR TABLE:") mycursor.execute("SELECT * FROM CAR") all_data = mycursor.fetchall() if all_data: for row in all_data: print(str(row) + "\t" + row + "\t" + row + "\t" + row + "\t" + str(row) + "\t" + str(row)) print() elif ch == 4: CCODE = int(input("ENTER CAR NUMBER: ")) print() mycursor.execute("DELETE FROM CAR WHERE CCODE = %s", (CCODE,)) mydb.commit() print("CAR RECORD DELETED") print() mycursor.execute("SELECT * FROM CAR WHERE CCODE = %s", (CCODE,)) data = mycursor.fetchall() if not data: print("NO CARS FOUND WITH CAR NUMBER", CCODE) else: print("CARS WITH CAR NUMBER", CCODE) for row in data: print(str(row)+"\t"+row+"\t"+row+"\t"+row+"\t"+str(row)+"\t"+s tr(row)) print() print("\nUPDATED CAR TABLE:") mycursor.execute("SELECT * FROM CAR") all_data = mycursor.fetchall() if all_data: for row in all_data: print(str(row) + "\t" + row + "\t" + row + "\t" + row + "\t" + str(row) + "\t" + str(row)) else: print("NO CAR RECORDS FOUND.") print() elif ch==0: print('Exiting the program now!') Output: 1. TO ACCEPT NEW CAR DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY CAR NUMBER 3. TO UPDATE THE CHARGE BY CAR NUMBER 4. TO DELETE RECORD BY CAR NUMBER ENTER 0 TO EXIT ENTER CHOICE: 1 TABLE HAS BEEN CREATED ENTER TOTAL NUMBER OF CARS: 5 ENTER CAR CODE/NUMBER: 501 ENTER CAR NAME: A-Star ENTER CAR COMPANY: Suzuki ENTER COLOUR OF CAR: RED ENTER CAR CAPACITY: 3 ENTER CAR CHARGE: 140 RECORD HAS BEEN INSERTED ENTER CAR CODE/NUMBER: 502 ENTER CAR NAME: Innova ENTER CAR COMPANY: Toyota ENTER COLOUR OF CAR: WHITE ENTER CAR CAPACITY: 7 ENTER CAR CHARGE: 300 RECORD HAS BEEN INSERTED ENTER CAR CODE/NUMBER: 503 ENTER CAR NAME: Indigo ENTER CAR COMPANY: Tata ENTER COLOUR OF CAR: SILVER ENTER CAR CAPACITY: 3 ENTER CAR CHARGE: 120 RECORD HAS BEEN INSERTED ENTER CAR CODE/NUMBER: 509 ENTER CAR NAME: SX4 ENTER CAR COMPANY: Suzuki ENTER COLOUR OF CAR: SILVER ENTER CAR CAPACITY: 4 ENTER CAR CHARGE: 200 RECORD HAS BEEN INSERTED ENTER CAR CODE/NUMBER: 510 ENTER CAR NAME: C Class ENTER CAR COMPANY: Mercedes ENTER COLOUR OF CAR: RED ENTER CAR CAPACITY: 4 ENTER CAR CHARGE: 450 RECORD HAS BEEN INSERTED 501 A-Star Suzuki RED 3 140 502 Innova Toyota WHITE 7 300 503 Indigo Tata SILVER 3 120 509 SX4 Suzuki SILVER 4 200 510 C Class Mercedes RED 4 450 1. TO ACCEPT NEW CAR DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY CAR NUMBER 3. TO UPDATE THE CHARGE BY CAR NUMBER 4. TO DELETE RECORD BY CAR NUMBER ENTER 0 TO EXIT ENTER CHOICE: 2 ENTER CAR NUMBER: 510 CARS WITH CAR NUMBER 510 510 C Class Mercedes RED 4 450 1. TO ACCEPT NEW CAR DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY CAR NUMBER 3. TO UPDATE THE CHARGE BY CAR NUMBER 4. TO DELETE RECORD BY CAR NUMBER ENTER 0 TO EXIT ENTER CHOICE: 3 ENTER CAR NUMBER: 510 ENTER THE UPDATED CHARGE OF CAR: 550 CHARGE HAS BEEN UPDATED CARS WITH CAR NUMBER 510 510 C Class Mercedes RED 4 550 UPDATED CAR TABLE: 501 A-Star Suzuki RED 3 140 502 Innova Toyota WHITE 7 300 503 Indigo Tata SILVER 3 120 509 SX4 Suzuki SILVER 4 200 510 C Class Mercedes RED 4 550 1. TO ACCEPT NEW CAR DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY CAR NUMBER 3. TO UPDATE THE CHARGE BY CAR NUMBER 4. TO DELETE RECORD BY CAR NUMBER ENTER 0 TO EXIT ENTER CHOICE: 4 ENTER CAR NUMBER: 509 CAR RECORD DELETED NO CARS FOUND WITH CAR NUMBER 509 UPDATED CAR TABLE: 501 A-Star Suzuki RED 3 140 502 Innova Toyota WHITE 7 300 503 Indigo Tata SILVER 3 120 510 C Class Mercedes RED 4 550 1. TO ACCEPT NEW CAR DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY CAR NUMBER 3. TO UPDATE THE CHARGE BY CAR NUMBER 4. TO DELETE RECORD BY CAR NUMBER ENTER 0 TO EXIT ENTER CHOICE: 0 EXITING THE PROGRAM NOW SQL - 7. Create a table TEACHER in MySQL. Design a menu driven API using Python Connectivity to : ACCEPT new details. SEARCH by TID and DISPLAY details UPDATE records DELETE Record Source Code: import mysql.connector mydb = mysql.connector.connect(host='localhost',user='root',password='12345',database ='PRACTICAL') mycursor = mydb.cursor() while True: print() print("1. TO ACCEPT NEW TEACHER DETAILS AND DISPLAY ALL RECORDS") print("2. TO DISPLAY DETAILS BY TID") print("3. TO UPDATE THE RECORDS BY TID") print("4. TO DELETE RECORD BY TID") print("ENTER 0 TO EXIT") print() ch = int(input("ENTER CHOICE: ")) print() if ch == 0: print("EXITING THE PROGRAM NOW") break elif ch == 1: mycursor.execute("CREATE TABLE IF NOT EXISTS TEACHER(tid integer, name varchar(20), deptid integer, age integer, salary integer, gender char(1))") print("TABLE HAS BEEN CREATED") mydb.commit() print() n = int(input("ENTER TOTAL NUMBER OF TEACHERS: ")) print() for i in range(n): tid = int(input("ENTER TEACHER ID: ")) name = input("ENTER NAME OF TEACHER: ") deptid = int(input("ENTER DEPTID: ")) age = int(input("ENTER AGE OF TEACHER: ")) salary = int(input("ENTER TEACHER SALARY: ")) gender = input("ENTER GENDER OF TEACHER: ") print() mycursor.execute("INSERT INTO TEACHER (tid, name, deptid, age, salary, gender) VALUES (%s, %s, %s, %s, %s, %s)",(tid, name, deptid, age, salary, gender)) print("RECORD HAS BEEN INSERTED") print() mycursor.execute("SELECT * FROM TEACHER") data = mycursor.fetchall() if not data: print("NO TEACHER RECORDS FOUND") else: for row in data: print(str(row)+"\t"+row+"\t"+str(row)+"\t"+str(row)+"\t"+str(row )+"\t"+row) print() elif ch == 2: tid = int(input("ENTER TEACHER ID: ")) print() mycursor.execute("SELECT * FROM TEACHER WHERE tid = %s", (tid,)) data = mycursor.fetchall() if not data: print("NO TEACHERS FOUND WITH ID", tid) else: print("TEACHERS WITH ID", tid) for row in data: print(str(row)+"\t"+row+"\t"+str(row)+"\t"+str(row)+"\t"+str(row )+"\t"+row) print() elif ch == 3: tid = int(input("ENTER TEACHER NUMBER: ")) print() salary = input("ENTER THE UPDATED SALARY OF TEACHER: ") print() mycursor.execute("UPDATE TEACHER SET salary = %s WHERE tid = %s", (salary, tid)) mydb.commit() print("SALARY HAS BEEN UPDATED") elif ch==4: tid = int(input("ENTER TEACHER NUMBER: ")) print() mycursor.execute("DELETE FROM TEACHER WHERE tid = %s", (tid,)) mydb.commit() print("TEACHER RECORD DELETED") print() elif ch==0: print("Éxiting program!") Output: 1. TO ACCEPT NEW TEACHER DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY TID 3. TO UPDATE THE RECORDS BY TID 4. TO DELETE RECORD BY TID ENTER 0 TO EXIT ENTER CHOICE: 1 TABLE HAS BEEN CREATED ENTER TOTAL NUMBER OF TEACHERS: 8 ENTER TEACHER ID: 1 ENTER NAME OF TEACHER: JUGAL ENTER DEPTID: 103 ENTER AGE OF TEACHER: 34 ENTER TEACHER SALARY: 12000 ENTER GENDER OF TEACHER: M RECORD HAS BEEN INSERTED ENTER TEACHER ID: 2 ENTER NAME OF TEACHER: SHARMILLA ENTER DEPTID: 101 ENTER AGE OF TEACHER: 31 ENTER TEACHER SALARY: 20000 ENTER GENDER OF TEACHER: F RECORD HAS BEEN INSERTED ENTER TEACHER ID: 3 ENTER NAME OF TEACHER: SANDEEP ENTER DEPTID: 102 ENTER AGE OF TEACHER: 32 ENTER TEACHER SALARY: 30000 ENTER GENDER OF TEACHER: M RECORD HAS BEEN INSERTED ENTER TEACHER ID: 4 ENTER NAME OF TEACHER: SANGEETA ENTER DEPTID: 101 ENTER AGE OF TEACHER: 35 ENTER TEACHER SALARY: 40000 ENTER GENDER OF TEACHER: F RECORD HAS BEEN INSERTED ENTER TEACHER ID: 5 ENTER NAME OF TEACHER: RAKESH ENTER DEPTID: 102 ENTER AGE OF TEACHER: 42 ENTER TEACHER SALARY: 25000 ENTER GENDER OF TEACHER: M RECORD HAS BEEN INSERTED ENTER TEACHER ID: 6 ENTER NAME OF TEACHER: SHYAM ENTER DEPTID: 101 ENTER AGE OF TEACHER: 50 ENTER TEACHER SALARY: 15000 ENTER GENDER OF TEACHER: M RECORD HAS BEEN INSERTED ENTER TEACHER ID: 7 ENTER NAME OF TEACHER: SHIVA ENTER DEPTID: 103 ENTER AGE OF TEACHER: 44 ENTER TEACHER SALARY: 9000 ENTER GENDER OF TEACHER: M RECORD HAS BEEN INSERTED ENTER TEACHER ID: 8 ENTER NAME OF TEACHER: SHILPA ENTER DEPTID: 102 ENTER AGE OF TEACHER: 33 ENTER TEACHER SALARY: 20000 ENTER GENDER OF TEACHER: F RECORD HAS BEEN INSERTED 1 JUGAL 103 34 12000 M 2 SHARMILLA 101 31 20000 F 3 SANDEEP 102 32 30000 M 4 SANGEETA 101 35 40000 F 5 RAKESH 102 42 25000 M 6 SHYAM 101 50 15000 M 7 SHIVA 103 44 9000 M 8 SHILPA 102 33 20000 F 1. TO ACCEPT NEW TEACHER DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY TID 3. TO UPDATE THE RECORDS BY TID 4. TO DELETE RECORD BY TID ENTER 0 TO EXIT ENTER CHOICE: 2 ENTER TEACHER ID: 2 TEACHERS WITH ID 2 2 SHARMILLA 101 31 20000 F 1. TO ACCEPT NEW TEACHER DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY TID 3. TO UPDATE THE RECORDS BY TID 4. TO DELETE RECORD BY TID ENTER 0 TO EXIT ENTER CHOICE: 3 1. TO ACCEPT NEW TEACHER DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY TID 3. TO UPDATE THE RECORDS BY TID 4. TO DELETE RECORD BY TID ENTER 0 TO EXIT ENTER CHOICE: 3 ENTER TEACHER NUMBER: 4 ENTER THE UPDATED SALARY OF TEACHER: 35000 SALARY HAS BEEN UPDATED 1. TO ACCEPT NEW TEACHER DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY TID 3. TO UPDATE THE RECORDS BY TID 4. TO DELETE RECORD BY TID ENTER 0 TO EXIT ENTER CHOICE: 4 ENTER TEACHER NUMBER: 5 TEACHER RECORD DELETED 1. TO ACCEPT NEW TEACHER DETAILS AND DISPLAY ALL RECORDS 2. TO DISPLAY DETAILS BY TID 3. TO UPDATE THE RECORDS BY TID 4. TO DELETE RECORD BY TID ENTER 0 TO EXIT ENTER CHOICE: 0 EXITING THE PROGRAM NOW