CS Practical File
CS Practical File
Q1. Write the python program to print your name using a function.
Ans.
def print_name():
name = "Atharva"
print("My name is ", name)
Q2. Write the python program using functions to add and subtract
two values and return.
Ans.
def add(a, b):
return a + b
greet(‘bob’, ’ hi’)
greet(‘daniel’)
Q5. Write the python code to show the working of keyword
arguments.
Ans.
def describe_pet(animal_type, pet_name):
print(f"\nI have a {animal_type}.")
print(f"My {animal_type}'s name is {pet_name.title()}.")
describe_pet(animal_type='dog', pet_name='willie')
describe_pet(pet_name='whiskers', animal_type='cat')
Q6. Write the python code to show the global and local scope of a
variable.
Ans.
x = 10
def my_function():
y=5
print("Inside the function, x (global):", x)
print("Inside the function, y (local):", y)
print("Outside the function, x (global):", x)
try:
print("Outside the function, y (local):", y)
except NameError as e:
print("Error:", e)
Q7. Write the MySQL command to create the database db.
Ans.
CREATE DATABASE db;
Q8. Write the MySQL command to create a student table with the
student_id, class, section, gender, name, dob, and marks as
attributes where the student id is the primary key.
Ans.
CREATE TABLE student (
student_id INT PRIMARY KEY,
class varchar(10),
section CHAR(1),
gender CHAR(1),
name VARCHAR(100),
dob DATE,
marks INT
);
Q9. Write the MySQL command to insert the details of at least 5
students in the above table.
Ans.
INSERT INTO student (student_id, class, section, gender, name, dob, marks) VALUES
(1, '10', 'A', 'M', 'John Doe', '2005-05-15', 85),
(2, '10', 'B', 'F', 'Jane Smith', '2005-08-22', 90),
(3, '9', 'A', 'M', 'Mike Johnson', '2006-11-30', 78),
(4, '9', 'B', 'F', 'Emily Davis', '2006-03-12', 88),
(5, '8', 'C', 'M', 'Chris Brown', '2007-07-19', 92);
Q10. Write the MySQL command to display the entire content of the
table.
Ans.
SELECT * FROM students;
Q11. Write the MySQL command to add an email column in the
above student table and also show the structure of the student
table after addition of the column
Ans.
ALTER TABLE student
ADD COLUMN email VARCHAR(100);
DESCRIBE student;