Added sql
This commit is contained in:
33
jokes-bot-v3.0/jokes_v3.py
Normal file
33
jokes-bot-v3.0/jokes_v3.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# simple_joke_menu.py
|
||||
import sqlite3
|
||||
import random
|
||||
|
||||
db = sqlite3.connect('jokes.db')
|
||||
|
||||
while True:
|
||||
print("\n1. Get joke")
|
||||
print("2. Add joke")
|
||||
print("3. Quit")
|
||||
|
||||
choice = input("Your choice: ")
|
||||
|
||||
if choice == "1":
|
||||
joke = db.execute("SELECT joke FROM jokes ORDER BY RANDOM() LIMIT 1").fetchone()
|
||||
if joke:
|
||||
print(f"\n🤣 {joke[0]}")
|
||||
else:
|
||||
print("No jokes yet!")
|
||||
|
||||
elif choice == "2":
|
||||
new = input("Your joke: ")
|
||||
if new:
|
||||
name = input("Your name: ") or "Friend"
|
||||
db.execute("INSERT INTO jokes (joke, contributor) VALUES (?, ?)", (new, name))
|
||||
db.commit()
|
||||
print("Saved!")
|
||||
|
||||
elif choice == "3":
|
||||
break
|
||||
|
||||
db.close()
|
||||
print("Bye!")
|
||||
Reference in New Issue
Block a user