maroph

db_pick_random.py

Nov 16th, 2019
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. import sqlite3
  2. from random import randint
  3.  
  4. conn = sqlite3.connect("computer_cards.db")
  5.  
  6.  
  7. def read_all_cards():
  8.     result = conn.execute("SELECT * FROM computer")
  9.     return result.fetchall()
  10.  
  11.  
  12. def pick_card():
  13.     cards = read_all_cards()
  14.     random_card = cards[randint(0, len(cards) - 1)]
  15.     return random_card
  16.  
  17.  
  18. resp = "y"
  19. while resp == "y":
  20.     print(pick_card())
  21.     resp = input("pick another card?[y/n]:")
  22.  
  23. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment