Sunday, June 27, 2021

Re: python code

Hello sir,
I am trying to run the 'if else' query for a valid item name but my else is not running. and it is showing an error for invalid item name. For example, I have a 'pen' in my database. If I input the 'pen', the program runs but if I input 'penn' instead of showing the output print 'valid itam name' it is showing an error.
Please help me.

On Sun, Jun 27, 2021 at 3:37 PM mayank sandikar <mayanksandikar191098@gmail.com> wrote:
import  sqlite3
from datetime import date,time


curr_date = date.today()
conn  =  sqlite3.connect( 'mydatabase.db' )
cursor  =  conn.cursor ()

v  = input("enter itemname ")
cursor.execute("SELECT basicquantity FROM local WHERE `itamname`=?",[v])

itamname = cursor.fetchone()[0]
date = curr_date.strftime('%Y-%m-%d')

cursor.execute("SELECT basicquantity   from  local WHERE itamname=?",[v,])
result = cursor.fetchone()[0]

cursor.execute("SELECT SUM(userquantity) FROM local WHERE itamname=?",[v,])
c = cursor.fetchall()[0][0]
print("SUM",c)

o = result - c 
print("subtraction",o)


if itamname:
    r  = int(input("enter quantity"))
    if r < o or r == o:
        conn.execute('''insert into local
            select   ? ,po , itamno,itamname,basicquantity,rate, ? 
            from local 
            where itamname= ? ORDER BY itamname DESC LIMIT 1;''',[date, r,v])  
    else:
        print("quantity grater than inventry"
else:

    print("insert valid itemname ")
    
conn.commit()
conn.close()


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOS5mPwYMdDFu47m%2BEC6ei4HzYnvzYPKibdO9PJkLUzV3vA89w%40mail.gmail.com.

No comments:

Post a Comment