Uncategorized

mysql – My python code doesn’t show any error when I run it but I’m not getting the desired output



I’m writing a code for my school project using Python. Topic: “School management system”.

Here I’m facing two problems:

  1. No output.
  2. Infinite loop.

There are 4 tables in my “mysch” database: students,teacher,fees and bills.

Here,neither do I get an error nor an output:

Code:

    def dFees():
        sd=input("Date : ")
        sql="select * from Fees"
        c=con.cursor()
        c.execute(sql)
        d=c.fetchall()
        for i in d:
            if i[3]==sd:
                print("Name : ",i[0],"\n","Registration : ",i[1],"\n","Fee : ",i[2],"\n","Date : ",i[3],"\n","Phone : ",i[4])
            print("-----------------------")
        options()

Again in this code block, I get an infinite loop even after using the break statement:

    def dBills():
        sql = "select * from Bills"
        c = con.cursor()
        c.execute(sql)
        d = c.fetchall()
        for i in d:
            print("Detail : ", i[0], "\n", "Cost : ", i[1], "\n", "Date : ", i[2])
            print("-----------------------")
            break

My entire code:

c = con.cursor()
c.execute("show databases")
dl = c.fetchall()
dl2 = []
for i in dl:
    dl2.append(i[0])  # For only the names
if 'mysch' in dl2:
    sql = "use mysch"
    c.execute(sql)
else:  # Create database if not exists
    sql1 = "create database mysch"
    c.execute(sql1)
    sql2 = "use mysch"
    c.execute(sql2)
    sql3 = """create table Students(Name varchar(50),Registration varchar(50),Class varchar(10),RollNumber int,
    Date DATE)"""
    c.execute(sql3)
    sql4 = """create table Fees(Name varchar(20),Registration varchar(25),Fee int,Date DATE,
    Phone bigint)"""
    c.execute(sql4)
    sql5 = """create table Bills(Detail varchar(20),Cost int,Date DATE)"""
    c.execute(sql5)
    sql6 = """create table Teacher(Name varchar(100),Work varchar(20),Salary int)"""
    c.execute(sql6)
    con.commit()


# SYSTEM PASSWORD LOGIN
def signin():
    print("\n")
    print("        ---------->>>>>>>>>>>Welcome to KENDRIYA VIDYALAYA NAMRUP<<<<<<<<<<----------        ")
    print("\n")
    p = input("System password : ")
    if p == "kvnamrup":
        options()
    else:
        print("Incorrect password")
        signin()


# PROJECT WORKING OPTIONS
def options():
    print("""
                ~KENDRIYA VIDYALAYA NAMRUP~
        ..........................................
        1. Add Student          5. Display students
        2. Pay fees             6. Display Fees
        3. Add bill             7. Display Bills
        4. Add teacher          8. Display Teachers
        ..........................................
        """)
    choice = input("Select option : ")
    while True:
        if choice == '1':
            AddStudent()
        elif choice == '2':
            PayFees()
        elif choice == '3':
            AddBill()
        elif choice == '4':
            AddTeacher()
        elif choice == '5':
            dStudents()
        elif choice == '6':
            dFees()
        elif choice == '7':
            dBills()
        elif choice == '8':
            dTeacher()
        else:
            print("""Invalid Option
                     Enter again""")
            options()


def AddStudent():
    n = input("Name : ")
    r = input("Registration : ")
    c = input("Class : ")
    rn = int(input("Roll number : "))
    d = input("Date : ")
    data = (n, r, c, rn, d)
    sql = "insert into Students values(%s, %s, %s, %s, %s)"
    c = con.cursor()
    c.execute(sql, data)
    con.commit()
    print("Data Inserted Successfully")
    options()


def PayFees():
    n = input("Name : ")
    r = input("Registration : ")
    f = input("Fee : ")
    d = input("Date : ")
    p = input("Phone : ")
    data = (n, r, f, d, p)
    sql = "insert into Fees values(%s, %s, %s, %s, %s)"
    c = con.cursor()
    c.execute(sql, data)
    con.commit()
    print("Data Inserted Successfully")
    options()


def AddBill():
    dt = input("Detail : ")
    c = input("Cost : ")
    d = input("Date : ")
    data = (dt, c, d)
    sql = "insert into Bills values(%s, %s, %s)"
    c = con.cursor()
    c.execute(sql, data)
    con.commit()
    print("Data Inserted Successfully")
    options()


def AddTeacher():
    n = input("Name : ")
    w = input("Work : ")
    s = input("Salary : ")
    data = (n, w, s)
    sql = "insert into Teacher values(%s, %s, %s)"
    c = con.cursor()
    c.execute(sql, data)
    con.commit()
    print("Data Inserted Successfully")
    options()


def dStudents():
    cl = input("Class : ")
    sql = "select * from Students"
    c = con.cursor()
    c.execute(sql)
    d = c.fetchall()
    for i in d:
        if i[2] == cl:
            print("Name : ", i[0], "\n", "Registration : ", i[1], "\n", "Class : ", i[2], "\n", "Roll number : ", i[3],
                  "\n", "Date : ", i[4])
            print("---------------------------")
    options()


def dFees():
    sd = input("Date : ")
    sql = "select * from Fees"
    c = con.cursor()
    c.execute(sql)
    d = c.fetchall()
    for i in d:
        if i[3] == sd:
            print("Name : ", i[0], "\n", "Registration : ", i[1], "\n", "Fee : ", i[2], "\n", "Date : ", i[3], "\n",
                  "Phone : ", i[4])
            print("-----------------------")
    options()


def dBills():
    sql = "select * from Bills"
    c = con.cursor()
    c.execute(sql)
    d = c.fetchall()
    for i in d:
        print("Detail : ", i[0], "\n", "Cost : ", i[1], "\n", "Date : ", i[2])
        print("-----------------------")
        break


def dTeacher():
    sql = "select * from Teacher"
    c = con.cursor()
    c.execute(sql)
    d = c.fetchall()
    for i in d:
        print("Name : ", i[0], "\n", "Work : ", i[1], "\n", "Salary : ", i[2])
        print("---------------------")
    options()


signin()



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *