Add valid answer checking
This commit is contained in:
parent
1ac1b67fb8
commit
68e3b2c1fc
1 changed files with 25 additions and 5 deletions
30
main.py
30
main.py
|
@ -14,13 +14,15 @@ answerKey = []
|
||||||
answer = "0"
|
answer = "0"
|
||||||
answerCount = 0
|
answerCount = 0
|
||||||
key = False
|
key = False
|
||||||
|
validAnswers = []
|
||||||
|
|
||||||
if len(keys) > 1:
|
if len(keys) > 1:
|
||||||
key = fp.menu(keys, "Please select an assignment to grade")
|
key = fp.menu(keys, "Please select an assignment to grade")
|
||||||
fp.clear()
|
fp.clear()
|
||||||
if key:
|
if key:
|
||||||
answerKey = key
|
answerKey = key["key"]
|
||||||
answerCount = len(key)
|
answerCount = len(key["key"])
|
||||||
|
validAnswers = key["valid"]
|
||||||
else:
|
else:
|
||||||
while not False:
|
while not False:
|
||||||
answer = fp.replitInput(
|
answer = fp.replitInput(
|
||||||
|
@ -38,12 +40,21 @@ else:
|
||||||
answerCount += 1
|
answerCount += 1
|
||||||
answerKey.append(answer)
|
answerKey.append(answer)
|
||||||
name = fp.replitInput("Please enter the name of this assignment")
|
name = fp.replitInput("Please enter the name of this assignment")
|
||||||
keys[name] = answerKey
|
validAnswers = list(
|
||||||
|
fp.replitInput("Please enter the valid answers to this assignment").upper()
|
||||||
|
)
|
||||||
|
keys[name] = {"key": answerKey, "valid": validAnswers}
|
||||||
with open("assignments.py", "w") as file:
|
with open("assignments.py", "w") as file:
|
||||||
file.write(f"keys = {keys}")
|
file.write(f"keys = {keys}")
|
||||||
|
|
||||||
fp.clear()
|
fp.clear()
|
||||||
|
|
||||||
|
tDigits = 1
|
||||||
|
tmp = answerCount
|
||||||
|
while tmp > 10:
|
||||||
|
tmp = tmp / 10
|
||||||
|
tDigits += 1
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
right = 0
|
right = 0
|
||||||
try:
|
try:
|
||||||
|
@ -61,11 +72,20 @@ while 1:
|
||||||
if multi.upper() != "N":
|
if multi.upper() != "N":
|
||||||
queue = list(answer)
|
queue = list(answer)
|
||||||
answer = queue.pop(0)
|
answer = queue.pop(0)
|
||||||
|
aDigits = 0
|
||||||
|
tmp = i + 1
|
||||||
|
while tmp > 10:
|
||||||
|
aDigits += 1
|
||||||
|
tmp = tmp / 10
|
||||||
|
digits = tDigits - aDigits
|
||||||
|
space = " " * digits
|
||||||
if answer == answerKey[i]:
|
if answer == answerKey[i]:
|
||||||
right += 1
|
right += 1
|
||||||
print(f" Answer {i + 1} is correct")
|
print(f"++ Answer {space}{i + 1} is correct")
|
||||||
|
elif answer in validAnswers:
|
||||||
|
print(f"-- Answer {space}{i + 1} is incorrect")
|
||||||
else:
|
else:
|
||||||
print(f" Answer {i + 1} is incorrect")
|
print(f"?? Answer {space}{i + 1} is N/A")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
print(
|
print(
|
||||||
|
|
Loading…
Reference in a new issue