computer science practical assignment XII
computer science practical assignment XII
Code:-
f=1
if num==0:
else:
for i in range(num,0,-1):
f=f*i
output:-
the factorial of 54 is
230843697339241380472092742683027581083278564571807941132288000000000000
Code-
l=len(a)
n=l
b=0
while l>0:
c=int(a[l-1])
d=c**n
l=l-1
b=b+d
if int(a)==b:
else:
output-
Code-
l=len(a)
for i in range(l-1,-1,-1):
print(a[i],end="")
output:-
hello = olleh
hello = olleh
Copy code
Output:
less
Copy code
python
Copy code
if operation == "add":
return a + b
return a - b
return a * b
else:
python
Copy code
def calculate(data):
if name[0].lower() in 'aeiou':
total = sum(marks)
students = {
calculate(students)
python
Copy code
if c == char:
return True
return False
python
Copy code
def count_vowels(string):
vowels = "aeiou"
count = 0
if char in vowels:
count += 1
return count
count = count_vowels(string)
if count > 0:
else:
6. Dice simulator
python
Copy code
import random
def roll_dice():
return random.randint(1, 6)
python
Copy code
class Stack:
def __init__(self):
self.stack = []
def push(self, item):
self.stack.append(item)
def pop(self):
if not self.is_empty():
return self.stack.pop()
def is_empty(self):
return len(self.stack) == 0
# Testing
s = Stack()
s.push(10)
s.push(20)
print(s.pop()) # 20
print(s.pop()) # 10
sql
Copy code
Empname VARCHAR(50),
Desig VARCHAR(50),
Dept VARCHAR(50),
Age INT,
Place VARCHAR(50)
);
INSERT INTO Employee VALUES (6, 'Neha', 'Tester', 'QA', 27, 'Hyderabad');
INSERT INTO Employee VALUES (7, 'Anil', 'Consultant', 'Finance', 35, 'Pune');
sql
Copy code
DeptName VARCHAR(50)
);
EmpName VARCHAR(50),
DeptID INT,
);
sql
Copy code
-- Inner Join
FROM Employee
-- Left Join
FROM Employee
LEFT JOIN Department ON Employee.DeptID = Department.DeptID;
-- Right Join
FROM Employee
14. SQL Commands to Use Group By, Order By, and Having
sql
Copy code
FROM Employee
GROUP BY DeptID
sql
Copy code
python
Copy code
import sqlite3
conn = sqlite3.connect('company.db')
cursor = conn.cursor()
record = cursor.fetchone()
print("Record:", record)
conn.close()
17. Update a Record Using Python and SQL
python
Copy code
import sqlite3
conn = sqlite3.connect('company.db')
cursor = conn.cursor()
conn.commit()
print("Record Updated")
conn.close()
18. Delete a Record Using Python and SQL
python
Copy code
import sqlite3
conn = sqlite3.connect('company.db')
cursor = conn.cursor()
conn.commit()
print("Record Deleted")
conn.close()
19. Operations on Travel Stack
python
Copy code
travel_stack.append([city, country])
def pop_element(travel_stack):
if travel_stack:
return travel_stack.pop()
# Example Usage
travel_stack = []
nlist = [
["Paris", "France", 4000],
push_element(travel_stack, nlist)
python
Copy code
payroll.append(emp)
# Example Usage
payroll = []
push_data(payroll, employees)
python
Copy code
def pop_data(payroll):
while payroll:
print(payroll.pop())
print("Stack underflow")
# Example Usage
python
Copy code
import pickle
def write_bin(emp_list):
pickle.dump(emp, file)
# Example Usage
employees = [("John", 45, "New York"), ("Sara", 30, "Delhi"), ("Mike", 50, "Paris")]
write_bin(employees)
23. Write Data to CSV File
python
Copy code
import csv
def write_csv(student_records):
writer = csv.writer(file)
writer.writerow(record)
# Example Usage
students = [("Alice", 10, 45), ("Bob", 11, 60), ("Charlie", 12, 30)]
write_csv(students)
24. Count Lines in CSV
python
Copy code
def count_csv():
python
Copy code
import pickle
def filter_bin():
try:
found = False
while True:
try:
record = pickle.load(file)
if record[0].startswith("S"):
print(record)
found = True
except EOFError:
break
if not found:
print("Not available")
except FileNotFoundError:
filter_bin()