51
Η get_initial_num_questions επιστρέφει την τιμή των ερωτήσεων που όρισε ο χρήστης κατά
την έναρξη του παιχνιδιού.
def get_initial_num_questions(user_id, topic):
with sqlite3.connect('topics.db') as conn:
cursor = conn.cursor()
#select the initial number of users questions for a topic
cursor.execute('SELECT initial_num_questions FROM user_topics WHERE user_id = ? AND
topic = ?', (user_id, topic))
result = cursor.fetchone()
if result:
#return the initial number of questions
return result[0]
else:
return 0
Η get_last_user_age επιστρέφει την ηλικία του τελευταίου χρήστη που εισήλθε.
def get_last_user_age():
conn = sqlite3.connect('topics.db')
cursor = conn.cursor()
#get user_age of the user with the max id/the last user
cursor.execute('SELECT user_age FROM users WHERE id = (SELECT MAX(id) FROM users)')
result = cursor.fetchone()
conn.close()
if result:
#return the last users age
return result[0]
else:
return None