mardi 12 mai 2020

How to implement the if statement properly

I have a snip of code listed here. Basically is a database containing motel room numbers. There are 5 rooms in the data base. Some are dirty and some are clean. What I want to do is list all of the rooms into the listbox whether they are dirty or not. I'm having trouble figuring out the correct if statement to use so that I will list all rooms and print '--Dirty' beside the ones that are dirty.

def viewrooms():
rooms = Toplevel()
rooms.title('Room List')
rooms.geometry("800x900+550+50")

roomlb = Listbox(rooms, height=40, width=30, font="12")
roomlb.place(x=300, y=20)

conn = sqlite3.connect('roominventory.db')
c = conn.cursor()
c.execute("SELECT * FROM rooms")
records = c.fetchall()

for record in records:
    if record[4]=="N":
         room = str(record[0:2])
         status = "--Dirty"

    roomlb.insert(END, room + status)

Aucun commentaire:

Enregistrer un commentaire