Advertisement
AtEchoOff

DB Practice Mini project

Jun 21st, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. import sqlite3
  2.  
  3. # Connect to the database
  4. conn = sqlite3.connect("quests.db")
  5. cursor = conn.cursor()
  6.  
  7. # Create the table if it doesn't exist
  8. cursor.execute('''
  9. CREATE TABLE IF NOT EXISTS quests (
  10. id INTEGER PRIMARY KEY AUTOINCREMENT,
  11. name TEXT NOT NULL,
  12. description TEXT,
  13. completed INTEGER DEFAULT 0
  14. )
  15. ''')
  16. conn.commit()
  17.  
  18. # === Menu Loop ===
  19. def main():
  20. while True:
  21. print("\n=== Quest Tracker ===")
  22. print("1. Add Quest")
  23. print("2. View Quests")
  24. print("3. Mark Quest as Completed")
  25. print("4. Delete Quest")
  26. print("5. Exit")
  27.  
  28. choice = input("Choose an option: ")
  29.  
  30. if choice == "1":
  31. add_quest()
  32. elif choice == "2":
  33. view_quests()
  34. elif choice == "3":
  35. complete_quest()
  36. elif choice == "4":
  37. delete_quest()
  38. elif choice == "5":
  39. break
  40. else:
  41. print("Invalid choice.")
  42.  
  43. conn.close()
  44.  
  45. # === Functions to be completed ===
  46.  
  47. def add_quest():
  48. # TODO: Prompt for name/description and insert into database
  49. pass
  50.  
  51. def view_quests():
  52. # TODO: Fetch and print all quests from the database
  53. pass
  54.  
  55. def complete_quest():
  56. # TODO: Mark a quest as completed using its ID
  57. pass
  58.  
  59. def delete_quest():
  60. # TODO: Delete a quest from the database using its ID
  61. pass
  62.  
  63. if __name__ == "__main__":
  64. main()
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement