python code

15 views
Skip to first unread message

mayank sandikar

unread,
Jun 27, 2021, 6:08:39 AM6/27/21
to django...@googlegroups.com
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()


mayank sandikar

unread,
Jun 27, 2021, 6:17:38 AM6/27/21
to django...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages