Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. import sqlite3
  2. connection = sqlite3.connect("db_books.db")
  3.  
  4. cursor = connection.cursor()
  5.  
  6. # delete
  7. #cursor.execute("""DROP TABLE books;""")
  8.  
  9. #sql_command = """
  10. #CREATE TABLE books (
  11. #Name Varchar(50),
  12. #Autor VARCHAR(20),
  13. #Geliehen INTEGER);"""
  14.  
  15. #cursor.execute(sql_command)
  16.  
  17. #sql_command = """INSERT INTO books (Name, Autor, Geliehen)
  18. #VALUES ("Der Stein der Weise", "J.K. Rowling", 5);"""
  19. #cursor.execute(sql_command)
  20.  
  21.  
  22. #sql_command = """INSERT INTO books (Name, Autor, Geliehen)
  23. #VALUES ("Der Hobbit", "J.R. R. Tolkien", 9);"""
  24. #cursor.execute(sql_command)
  25.  
  26.  
  27. #sql_command = """INSERT INTO books (Name, Autor, Geliehen)
  28. #VALUES ("Eine kurze Geschichte der Zeit", "Stephen Hawking", 14);"""
  29. #cursor.execute(sql_command)
  30.  
  31.  
  32.  
  33.  
  34. sql_command = """SELECT Name, Autor, Geliehen FROM books ORDER BY Geliehen DESC;"""
  35. cursor.execute(sql_command)
  36.  
  37. max = 0
  38. max2 = 0
  39. maxPosition = 0
  40. max2Position = 0
  41.  
  42. title_array = []
  43. count_array = []
  44. autor_array = []
  45.  
  46. row=cursor.fetchone()
  47. while (row!=None):
  48. count_array.append(row[2])
  49. autor_array.append(row[1])
  50. title_array.append(row[0])
  51. row = cursor.fetchone()
  52.  
  53. i = 0
  54. while i < len(count_array):
  55. if count_array[i] > max:
  56. maxPosition = i
  57. max = count_array[i]
  58. i += 1
  59.  
  60. titleMax = title_array[maxPosition]
  61. autorMax = autor_array[maxPosition]
  62.  
  63. count_array.pop(maxPosition)
  64. title_array.pop(maxPosition)
  65. autor_array.pop(maxPosition)
  66.  
  67. i = 0
  68. while i < len(count_array):
  69. if count_array[i] > max2:
  70. max2Position = i
  71. max2 = count_array[i]
  72. i += 1
  73.  
  74. titleMax2 = title_array[max2Position]
  75. autorMax2 = autor_array[max2Position]
  76.  
  77.  
  78. print("Platz 1 ist das Buch",titleMax,"von",autorMax,"mit",max,"Ausleihen.")
  79. print("Platz 2 ist das Buch",titleMax2,"von",autorMax2,"mit",max2,"Ausleihen.")
  80.  
  81.  
  82. connection.commit()
  83.  
  84. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement