Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def readScore():
- selection = input("What score would you like the read ? n 1 - Lowest score n 2 - Highest score n 3 - Average score... ")
- name = input("Please enter the name of the pupil...")
- classNo = input("Please enter the class of the pupil...")
- myFile = sqlite3.connect("scores.db")
- c = myFile.cursor()
- c.execute('SELECT score FROM scores WHERE name = (?) AND classNo = (?)', (name, classNo,))
- row = c.fetchall()
- print(row)
- try:
- if selection == "1":
- print (min(row))
- if selection == "2":
- print (max(row))
- if selection == "3":
- print (sum(row) /len(row))
- except:
- print("No scores for that student")
- myFile.commit()
- myFile.close()
- import random
- import os
- import time
- import sqlite3
- clear = lambda: os.system('cls')
- if os.path.exists("scores.db") == False:
- myFile = sqlite3.connect("scores.db")
- c = myFile.cursor()
- c.execute('''CREATE TABLE scores
- (
- name TEXT,
- classNo INT,
- score INT
- )
- ''')
- myFile.commit()
- myFile.close()
- def scoreText(name, classNo, score):
- myFile = sqlite3.connect("scores.db")
- c = myFile.cursor()
- c.execute('SELECT score FROM scores WHERE name = (?) AND classNo = (?)', (name, classNo,))
- scores = c.fetchall()
- if len(scores) == 3:
- del scores[0]
- scores.append(score)
- scores = ', '.join(map(str, scores))
- print(scores)
- c.execute('UPDATE scores SET score = (?) WHERE name = (?) AND classNo = (?)', (scores, name, classNo,))
- else:
- scores = ', '.join(map(str, scores))
- print(scores)
- c.execute('INSERT OR REPLACE INTO scores(score, name, classNo) VALUES(?,?,?) ', (score, name, classNo,))
- myFile.commit()
- myFile.close()
- def test():
- score = 0
- count = 0
- name = input("Please enter your name before starting the test...")
- classNo = input("Please enter your class number before starting the test...")
- clear()
- while count < 10:
- num1 = random.randint(0,10)
- num2 = random.randint(0,10)
- symbol = random.randint(0,2)
- if symbol == 0:
- answer = num1 + num2
- inAnswer = input("What is " + str(num1) + " + " + str(num2) + "?... ")
- clear()
- try:
- if int(inAnswer) == answer:
- print("Your answer was correct ! n")
- score = score + 1
- count = count + 1
- else:
- print("Your answer was incorrect n")
- count = count + 1
- except:
- print("Please enter a number - Try again")
- #time.sleep(1.5)
- clear()
- if symbol == 1:
- answer = num1 - num2
- inAnswer = input("What is " + str(num1) + " - " + str(num2) + "?... ")
- clear()
- try:
- if int(inAnswer) == answer:
- print("Your answer was correct ! n")
- score = score + 1
- count = count + 1
- else:
- print("Your answer was incorrect n")
- count = count + 1
- except:
- print("Please enter a number - Try again")
- #time.sleep(1.5)
- clear()
- if symbol == 2:
- answer = num1 * num2
- inAnswer = input("What is " + str(num1) + " X " + str(num2) + "?... ")
- clear()
- try:
- if int(inAnswer) == answer:
- print("Your answer was correct ! n")
- score = score + 1
- count = count + 1
- else:
- print("Your answer was incorrect n")
- count = count + 1
- except:
- print("Please enter a number - Try again")
- #time.sleep(1.5)
- clear()
- scoreText(name, classNo, score)
- print(name + " you have finished the test. Your score was..." + str(score))
- time.sleep(2)
- clear()
- menu()
- def readScore():
- selection = input("What score would you like the read ? n 1 - Lowest score n 2 - Highest score n 3 - Average score... ")
- name = input("Please enter the name of the pupil...")
- classNo = input("Please enter the class of the pupil...")
- myFile = sqlite3.connect("scores.db")
- c = myFile.cursor()
- c.execute('SELECT score FROM scores WHERE name = (?) AND classNo = (?)', (name, classNo,))
- row = c.fetchall()
- print(row)
- try:
- if selection == "1":
- print (min(row))
- if selection == "2":
- print (max(row))
- if selection == "3":
- print (sum(row) /len(row))
- except:
- print("No scores for that student")
- myFile.commit()
- myFile.close()
- time.sleep(2)
- clear()
- menu()
- def ClassSort():
- myFile = sqlite3.connect("scores.db")
- c = myFile.cursor()
- clear()
- classNo = input("Enter the class number you would like to sort... ")
- clear()
- type = input("How would you like to sort ? n 1 - Highest score, with students in alphabetical order n 2 - Highest score, highest to lowest n 3 - Average score, highest to lowest n... ")
- if type == "1":
- c.execute('SELECT name, score FROM scores WHERE classNo = (?)', (classNo,))
- row = c.fetchall()
- if type == "2":
- c.execute('SELECT name, score FROM scores WHERE classNo = (?)', (classNo,))
- row = c.fetchall()
- if type == "3":
- c.execute('SELECT name, score FROM scores WHERE classNo = (?)', (classNo,))
- row = c.fetchall()
- myFile.commit()
- myFile.close()
- def menu():
- selection = input("Press: n 1 - Run Test... n 2 - Read previous scores... n 3 - Sort class scores n... ")
- if selection == "1":
- test()
- if selection == "2":
- readScore()
- if selection == "3":
- ClassSort()
- menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement