Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NameError: name 'dishID' is not defined. Did you mean: 'dishid'?

this is the code of the following function

Function:

def dishID():
    query = 'select count(*), max(DishID) from Dish'
    cur.execute(query)
    fetch = cur.fetchall()
    for i in fetch:
        if i[0] == 0:
            return 1
        else:
            return (int(i[1]) + 1)

Error code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

dishname = input('Enter Dish Name: ')
        dishprice = input('Enter Dish Price: ')
        dishid = str(dishID())
        query = 'insert into Dish values({}, {}, {})'.format(
            dishname, dishprice, dishid)
        cur.execute(query)
        con.commit()
        print("Dish has added successfully")

Full code: https://srcb.in/l1RdtphmhF

This is code is restaurant Database management system. I am taking the help of mysql and making this system. all the functions work fine but when i call the dishID function it produces an error where it cant read the function. To be precise i want the code to work so it can insert some values

>Solution :

Okay I looked at your link and the issue is extremely simple; you defined the function dishID only after you actually call it. Here’s a simple example of this issue – here’s some code that works fine:

def test_function():
    print('hi')

test_function()
Output: hi

Versus this code, which references test_function before its definition:

test_function()

def test_function():
    print('hi')
Output: NameError: name 'test_function' is not defined
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading