Ashish File 3.0
Ashish File 3.0
Input:
Output:
2. WAP in Python to implement default andpositional
parameters
Input:
Output:
3. Write a program in Python to input the value of x andn and print
the sum of the following series
1+x+x^2+x^3+.......X^n
Input:
Output:
4. WAP in Python to read a text file and printthe
number of vowels and consonants in the file.
Input:
Output:
5. WAP in Python to read a text file and print theline or
paragraph starting with the letter 'S'
Input:
Output:
Output:
7. WAP in Python to create a binary file with name and rollnumber of the
students. Search for given roll number and a display the name of
student
Input:
Output:
8. WAP in Python to create a binary file with rollno, name and marks of
the students and update the marks of specific student
Input:
Output:
9. WAP in Python to create a binary file with eid,ename and
salary of the employees and update the salary of specific
employee.
Input:
Output:
10. WAP in Python to create a text file and remove the lines whichcontains
the letter ‘K’.
Input:
Output:
11. Create a binary file with 10 randomnumbers from 1
to 40 and print those numbers. .
Input:
Output:
12. Write a program in Python to create a CSV file with thedetails of
5 students (Roll no, Name, Marks).
Input:
Output:
13. WAP in python to read acsv file.
Input:
Output:
14. Write a menu driven program which insert, delete and displaythe details
of an employee such as eid, ename and salary using Stack.
Input:
Output:
15. Write a menu driven program which insert, delete and display.The details
of a book such as book id, book name and price using stack
Input:
Output:
16. Write a menu driven program which insert, deleteand display the
details of a student such as roll no, sname and course using stack.
Input:
Output:
Input:
Output:
if choice == 1: #
Add a new book
bid = int(input("Enter Book ID: ")) bname =
input("Enter Book Name: ") bprice =
float(input("Enter Book Price: "))
mycursor.execute("INSERT INTO book VALUES (%s, %s, %s)", (bid, bname, bprice))
con.commit()
print("Book added successfully.")
elif choice == 2: #
Display all books
mycursor.execute("SELECT * FROM book")
books = mycursor.fetchall() if
books:
print("\nBooks:")
for book in books:
print(f"ID: ,book*0+-, Name: ,book*1+-, Price: ,book*2+-") else:
print("No books found.")
elif choice == 3: #
Update book details
bid = int(input("Enter Book ID to update: ")) bname
= input("Enter new Book Name: ") bprice =
float(input("Enter new Book Price: "))
mycursor.execute(
"UPDATE book SET bname = %s, bprice = %s WHERE bid = %s",
(bname, bprice, bid)
)
con.commit() if
mycursor.rowcount > 0:
print("Book updated successfully.") else:
print("Book ID not found.")
elif choice == 4:
# Delete a book
bid = int(input("Enter Book ID to delete: "))
mycursor.execute("DELETE FROM book WHERE bid = %s", (bid,))
con.commit() if mycursor.rowcount > 0:
print("Book deleted successfully.") else:
print("Book ID not found.")
elif choice == 5: #
Exit the program
print("Exiting...")
break
Output:
21. Write a menu driven program to demonstrate add,
display, update, delete and exit. Performed
on a table product containing (id, name, price) through
python-MYSQL connectivity.
Input :
import mysql.connector
cursor = connection.cursor() id =
int(input("Enter Produ cursor = connection.cursor()
id = int(input("Enter Product ID to update: ")) name
= input("Enter new Product Name: ")
price = float(input("Enter new Product Price: ")) query = "UPDATE
product SET name=%s, price=%s WHERE id=%s" values = (name, price, id)
cursor.execute(query, values) connection.commit() if cursor.rowcount >
0:
print("Product updated successfully.") else:
print("Product not found.") except
Exception as e: print(f"Error: ,e-")
def main():
connection = connect_to_database() while
True:
print("\nMenu:") print("1.
Add Product") print("2. Display
Products") print("3. Update
Product") print("4. Delete
Product")
print("5. Exit")
choice = input("Enter your choice: ") if
choice == '1': add_product(connection)
elif choice == '2':
display_products(connection) elif choice
== '3': update_product(connection)
elif choice == '4':
delete_product(connection) elif choice ==
'5':
print("Exiting the program. Goodbye!")
connection.close()
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
output :
22. Write a menu driven program to demonstrate add,
display, update, delete and exit, performed on a table
club containing (id, name, city) through python-MYSQL
connectivity.
Input :
import mysql.connector
def main():
connection = connect_to_database() while
True:
print("\nMenu:")
print("1. Add Club")
print("2. Display Clubs")
print("3. Update Club")
print("4. Delete Club")
print("5. Exit")
choice = input("Enter your choice: ")
if choice == '1': add_club(connection)
elif choice == '2':
display_clubs(connection)
elif choice == '3':
update_club(connection) elif
choice == '4':
delete_club(connection) elif
choice == '5':
print("Exiting the program. Goodbye!")
connection.close()
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
main()
Output :
23. Write a menu driven program to demonstrate add, display,
update, delete and exit,
performed on a Student table containing (id,
name, course) through python-MYSQL connectivity
Input :
import mysql.connector
# Menu
def menu():
conn = connect_db() while
True:
choice = input("1. Add 2. Display 3. Update 4. Delete 5. Exit: ") if
choice == "1":
add_student(conn) elif
choice == "2":
display_students(conn) elif
choice == "3":
update_student(conn) elif
choice == "4":
delete_student(conn) elif
choice == "5": conn.close()
print("Goodbye!")
break
else:
print("Invalid choice!")
menu()
Output :
24. create a menu driven program to demonstrate add, display,
update, delete and exit.
Performed on a table movie containing (id, name, rating)
through python-MYSQL connectivity.
Input :
import mysql.connector
def add_movie(conn):
id, name, rating = input("Enter ID, Name, Rating: ").split(", ")
conn.cursor().execute("INSERT INTO movie (id, name, rating) VALUES (%s, %s, %s)",
(id, name, rating)) conn.commit()
def update_movie(conn):
id, name, rating = input("Enter ID, New Name, New Rating: ").split(", ")
conn.cursor().execute("UPDATE movie SET name=%s, rating=%s WHERE id=%s",
(name, rating, id)) conn.commit()
def delete_movie(conn):
id = input("Enter ID to delete: ")
conn.cursor().execute("DELETE FROM movie WHERE id=%s", (id,)) conn.commit()
def menu():
conn = connect_db() while
True:
choice = input("\n1.Add 2.Display 3.Update 4.Delete 5.Exit: ") if
choice == "1": add_movie(conn) elif choice == "2":
display_movies(conn) elif choice == "3": update_movie(conn) elif
choice == "4": delete_movie(conn) elif choice == "5": conn.close();
break
menu()
Output :
25. Write the SQL Query for full outer join of two
tables Emp
(id, name, salary, dept_id) and
Dept(dept_id, name)
Input :
27. Shiva is using a table with the following details:Students(Name, Class, Stream_id,
Stream_Name)
Write the SQL query to display the names of students who have not been assigned any stream or have been
assigned Stream_Name that end with "computers"
30. Shiva, a student of class XII, created a table "CLASS". Grade is one of the columnsof
this table. Write the SQL query to find the details of students whose grade have not
been entered.
31. Shiva is using a table employee. It hasfollowing details: Employee(Code, Name, Salary,
DeptCode). Write the SQL queryto display maximum salary department wise.
32. Write the SQL Query to display the differenceofhighest and
greater than4000
33. Write the SQL Query to increase 20% salary ofthe employee
whoseexperience is more than 5 year of the table Emp(id, name,
salary, exp)
34. Write the SQL Query for inner join of two tables Emp(eid,ename, salary,
dept_id) and Dept(dept_id, dname)
35. Write the SQL Query for full outer join of two tables Emp(eid,ename,
salary,dept_id) and Dept(dept_id, dname)
36. Write the SQL Query for full outer join of two tables Emp(eid, ename,salary,dept_id)
and Dept(dept_id, dname)
37. Display 4 characters extracted from 5th right characteronwards
from string 'ABCDEFG'.