हिंदी

Kabir wants to write a program in Python to insert the following record in the table named Student in MYSQL database, SCHOOL: rno(Roll number) - integer name(Name) - string DOB (Date of birth)

Advertisements
Advertisements

प्रश्न

Kabir wants to write a program in Python to insert the following record in the table named Student in MYSQL database,

SCHOOL:

  • rno(Roll number) - integer
  • name(Name) - string
  • DOB (Date of birth) - Date
  • Fee - float

Note the following to establish connectivity between Python and MySQL:

  • Username - root
  • Password - tiger
  • Host - localhost

The values of fields rno, name, DOB and fee has to be accepted from the user. Help Kabir to write the program in Python.

टिप्पणी लिखिए
Advertisements

उत्तर

import mysql.connector as mysql
con1 = mysql.connect (host="localhost", user="root", password="tiger", database="sample2023")
mycursor=con1.cursor()
rno = int (input ("Enter Roll Number:: "))
name = input(*Enter the name:: ")
DOB = input ("Enter date of birth::")
fee= float (input ("Enter Fee:: "))
query = "INSERT into student values{{},'{}','{}',{})".format (rno, name, DOB, fee)
mycursor.execute (query)
con1.commit()
print ("Data added successfully")
con1.close()
shaalaa.com
Data Types and Constraints in MySQL
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2023-2024 (March) Board Sample Paper
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×