Advertisement
Fahim999

Untitled

Nov 14th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import sqlite3
  2. from random import randint
  3. chand = sqlite3.connect("computer_cards.db")
  4.  
  5. #This function reads all the cards from the d/B
  6. def read_all_cards():
  7.     sql_all = "SELECT * FROM computer"
  8.     result = chand.execute(sql_all)
  9.     return result.fetchall()
  10.  
  11. #This function picks a random card
  12. def pick_card():
  13.     cards = read_all_cards()
  14.     random_card = cards[randint(0, len(cards) - 1)]
  15.     return random_card
  16.  
  17. #Now we can call these functions
  18. print('*******************************')
  19. print('WELCOME TO THE RANDOM CARD GAME')
  20. print('*******************************')
  21. print('')
  22. card = pick_card()
  23. print('Your random card is',card)
  24. first=card[0]
  25. print('Your computer is called:',first)
  26.  
  27. chand.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement