-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_questions.py
More file actions
38 lines (34 loc) · 851 Bytes
/
Copy pathmath_questions.py
File metadata and controls
38 lines (34 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import pandas as pd
import sys
import os
def run_program(id):
df = pd.read_csv('questions.csv')
df = df.reset_index()
score = 0
for index, row in df.iterrows():
answer = input(f"{row['term1']} * {row['term2']} = ")
try:
if int(answer) == int(row['answer']):
print('Correct!')
score += 1
else:
print('Incorrect')
except ValueError:
if answer == 'q':
break
else:
print("Please input an integer")
print('Current Score:', score)
#Saves the score
f = open(f"logs/{id}/{id}_math_score.txt", 'w')
f.write(str(score))
f.close()
#print(f"Score written to {sys.argv[1]}")
print("Final score:", score)
if __name__=="__main__":
f = open("participantID.txt", "r")
id = str.strip(f.read())
f.close()
if not os.path.exists(os.path.join("logs", id)):
os.makedirs(os.path.join("logs", id))
run_program(id)