Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- connection = sqlite3.connect("db_books.db")
- cursor = connection.cursor()
- # delete
- #cursor.execute("""DROP TABLE books;""")
- #sql_command = """
- #CREATE TABLE books (
- #Name Varchar(50),
- #Autor VARCHAR(20),
- #Geliehen INTEGER);"""
- #cursor.execute(sql_command)
- #sql_command = """INSERT INTO books (Name, Autor, Geliehen)
- #VALUES ("Der Stein der Weise", "J.K. Rowling", 5);"""
- #cursor.execute(sql_command)
- #sql_command = """INSERT INTO books (Name, Autor, Geliehen)
- #VALUES ("Der Hobbit", "J.R. R. Tolkien", 9);"""
- #cursor.execute(sql_command)
- #sql_command = """INSERT INTO books (Name, Autor, Geliehen)
- #VALUES ("Eine kurze Geschichte der Zeit", "Stephen Hawking", 14);"""
- #cursor.execute(sql_command)
- sql_command = """SELECT Name, Autor, Geliehen FROM books ORDER BY Geliehen DESC;"""
- cursor.execute(sql_command)
- max = 0
- max2 = 0
- maxPosition = 0
- max2Position = 0
- title_array = []
- count_array = []
- autor_array = []
- row=cursor.fetchone()
- while (row!=None):
- count_array.append(row[2])
- autor_array.append(row[1])
- title_array.append(row[0])
- row = cursor.fetchone()
- i = 0
- while i < len(count_array):
- if count_array[i] > max:
- maxPosition = i
- max = count_array[i]
- i += 1
- titleMax = title_array[maxPosition]
- autorMax = autor_array[maxPosition]
- count_array.pop(maxPosition)
- title_array.pop(maxPosition)
- autor_array.pop(maxPosition)
- i = 0
- while i < len(count_array):
- if count_array[i] > max2:
- max2Position = i
- max2 = count_array[i]
- i += 1
- titleMax2 = title_array[max2Position]
- autorMax2 = autor_array[max2Position]
- print("Platz 1 ist das Buch",titleMax,"von",autorMax,"mit",max,"Ausleihen.")
- print("Platz 2 ist das Buch",titleMax2,"von",autorMax2,"mit",max2,"Ausleihen.")
- connection.commit()
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement