Computer Science
A table, named STATIONERY, in ITEMDB database, has the following structure:
Field | Type |
---|---|
itemNo | int(11) |
itemName | varchar(15) |
price | float |
qty | int(11) |
Write the following Python function to perform the specified operation:
AddAndDisplay(): To input details of an item and store it in the table STATIONERY. The function should then retrieve and display all records from the STATIONERY table where the Price is greater than 120.
Assume the following for Python-Database connectivity:
Host: localhost, User: root, Password: Pencil
Python MySQL
15 Likes
Answer
import mysql.connector
def AddAndDisplay():
db = mysql.connector.connect(
host="localhost",
user="root",
password="Pencil",
database="ITEMDB"
)
cursor = db.cursor()
item_no = int(input("Enter Item Number: "))
item_name = input("Enter Item Name: ")
price = float(input("Enter Price: "))
qty = int(input("Enter Quantity: "))
insert_query = "INSERT INTO STATIONERY VALUES ({}, {}, {}, {})"
insert_query = insert_query.format(item_no, item_name, price, qty)
cursor.execute(insert_query)
db.commit()
select_query = "SELECT * FROM STATIONERY WHERE price > 120"
cursor.execute(select_query)
results = cursor.fetchall()
for record in results:
print(record)
AddAndDisplay()
Answered By
11 Likes
Related Questions
A csv file "Happiness.csv" contains the data of a survey. Each record of the file contains the following data:
- Name of a country
- Population of the country
- Sample Size (Number of persons who participated in the survey in that country)
- Happy (Number of persons who accepted that they were Happy)
For example, a sample record of the file may be:
[‘Signiland’, 5673000, 5000, 3426]
Write the following Python functions to perform the specified operations on this file:
(I) Read all the data from the file in the form of a list and display all those records for which the population is more than 5000000.
(II) Count the number of records in the file.
Saman has been entrusted with the management of Law University Database. He needs to access some information from FACULTY and COURSES tables for a survey analysis. Help him extract the following information by writing the desired SQL queries as mentioned below.
Table: FACULTY
F_ID FName LName Hire_Date Salary 102 Amit Mishra 12-10-1998 12000 103 Nitin Vyas 24-12-1994 8000 104 Rakshit Soni 18-5-2001 14000 105 Rashmi Malhotra 11-9-2004 11000 106 Sulekha Srivastava 5-6-2006 10000 Table: COURSES
C_ID F_ID CName Fees C21 102 Grid Computing 40000 C22 106 System Design 16000 C23 104 Computer Security 8000 C24 106 Human Biology 15000 C25 102 Computer Network 20000 C26 105 Visual Basic 6000 (I) To display complete details (from both the tables) of those Faculties whose salary is less than 12000.
(II) To display the details of courses whose fees is in the range of 20000 to 50000 (both values included).
(III) To increase the fees of all courses by 500 which have "Computer" in their Course names.
(IV)
(A) To display names (FName and LName) of faculty taking System Design.
OR
(B) To display the Cartesian Product of these two tables.
Surya is a manager working in a recruitment agency. He needs to manage the records of various candidates. For this, he wants the following information of each candidate to be stored:
- Candidate_ID – integer
- Candidate_Name – string
- Designation – string
- Experience – float
You, as a programmer of the company, have been assigned to do this job for Surya.
(I) Write a function to input the data of a candidate and append it in a binary file.
(II) Write a function to update the data of candidates whose experience is more than 10 years and change their designation to "Senior Manager".
(III) Write a function to read the data from the binary file and display the data of all those candidates who are not "Senior Manager".
Event Horizon Enterprises is an event planning organization. It is planning to set up its India campus in Mumbai with its head office in Delhi. The Mumbai campus will have four blocks/buildings - ADMIN, FOOD, MEDIA, DECORATORS. You, as a network expert, need to suggest the best network-related solutions for them to resolve the issues/problems mentioned in points (I) to (V), keeping in mind the distances between various blocks/buildings and other given parameters.
Block to Block distances (in Mtrs.)
From To Distance ADMIN FOOD 42 m ADMIN MEDIA 96 m ADMIN DECORATORS 48 m FOOD MEDIA 58 m FOOD DECORATORS 46 m MEDIA DECORATORS 42 m Distance of Delhi Head Office from Mumbai Campus = 1500 km
Number of computers in each of the blocks/Center is as follows:
ADMIN 30 FOOD 18 MEDIA 25 DECORATORS 20 DELHI HEAD OFFICE 18 (I) Suggest the most appropriate location of the server inside the MUMBAI campus. Justify your choice.
(II) Which hardware device will you suggest to connect all the computers within each building?
(III) Draw the cable layout to efficiently connect various buildings within the MUMBAI campus. Which cable would you suggest for the most efficient data transfer over the network?
(IV) Is there a requirement of a repeater in the given cable layout? Why/ Why not?
(V)
(A) What would be your recommendation for enabling live visual communication between the Admin Office at the Mumbai campus and the DELHI Head Office from the following options:
a) Video Conferencing
b) Email
c) Telephony
d) Instant MessagingOR
(B) What type of network (PAN, LAN, MAN, or WAN) will be set up among the computers connected in the MUMBAI campus ?