Page 26 - PYTHON-12
P. 26
(I) To display the names of guests staying in ‘Suite’ rooms.
(II) To show all bookings where the value of Total_Charges is greater than 500.
(III) To increase the room charges per night by 10% for room no. 310.
(IV) (A) To display the First_Name and Room_No of guests whose total cost is over 24000.
OR
(B) To display the Cartesian Product of GUESTS and BOOKINGS tables.
Ans. (I) Select First_Name, Last_Name from guests where Room_Type = "Suite";
(II) Select * from bookings where Total_Charges > 500;
(III) Update bookings set Room_Charges = Room_Charges + Room_Charges*0.1
where Room_No = 310;
(IV) (A) Select First_Name, Room_No from guests g, bookings b where
b.Total_Charges > 24000;
OR
(B) Select * from guests, bookings;
35. Table MOVIES in MOVIEDB database has the following structure: (4)
Field Type
movieID int(11)
movieName varchar(40)
genre varchar(20)
releaseYear int(4)
rating float
Write the following Python function to perform the specified operation:
Add_Display(): to input details of a movie and store it in the table MOVIES. The function should then retrieve
and display all records from MOVIES table where the rating is greater than 7.5.
Assume the following for Python-Database connectivity:
Host: localhost
User: admin
Password: movies123
Ans. def AddAndDisplay():
import mysql.connector as mycon
mydb=mycon.
connect(host="localhost",user="admin",passwd="movies123",database=
"MOVIEDB")
mycur=mydb.cursor()
mid=int(input("Enter Movie ID: "))
nm=input("Enter Movie Name: ")
gr=input("Enter Movie Genre: ")
year=int(input("Enter Movie Release Year: "))
rating=float(input("Enter Movie Rating"))
query="INSERT INTO movies(movieid, moviename, genre, releaseyear,
rating)VALUES (%s,%s,%s,%s,%s)"
A.12 Computer Science–XII