For a Computing task I have been asked to create a arithmetic quiz and to create a database system with the three requirements:
1.keep track of the scores each member of the class obtains in the quiz
2.three classes in the school
3.data should be kept separately for each class
Out of recommendation by my Computing teacher I decided to integrate my quiz with my database program. I have made leaps and bounds in actually making the program functional, but a particularly tricky part of the code remains:
form =''
while form == '':
form = input("Hello there. Are you in class A, class B, or class C? ")
if form == "Class a" or "Class A" or "a" or "A" or "class a" or "class A":
print("Your class is " +form)
myFile = open('classa.csv', 'a')
myFile.write("A\n")
elif form == "Class b" or "Class B" or "b" or "B" or "class b" or "class B":
print("Your class is " +form)
myFile = open('classb.csv', 'a')
myFile.write("B\n")
elif form == "Class c" or "Class C" or "c" or "C" or "class c" or "class C":
print("Your class is " +form)
myFile = open('classc.csv', 'a')
myFile.write("C\n")
else:
form = input("You can only input A, B or C. ")
I have tried researching online to attempt to assess a solution to my problem but I have found documentation on CSV and Python to be very poor - mostly reassurance that working with CSV is not hard, only for an unclear explanation. I have assessed that the following issues are at hand, but I am unsure on how to resolve:
- The validation part of the code does not work correctly. It is meant to simply repeat the question if the user inputs a response that is not part of the recognised list of inputs. The case is that the code happily accepts any input given to it, and it does not reject any input. Other attempts have gone in the opposite direction (any input is rejected, preventing the code from continuing). I cannot find a suitable Goldilocks zone for it.
- Writing to CSV does not work correctly. Mostly, it either ignores anything done in the quiz, or it overwrites the file completely, none of which are desirable outcomes. Curiously it only affects the classa.csv - classb.csv and classc.csv do not seem to have any interactive properties with the code.