So basically, I need to make a sort of sorting hat for a school project to see which study would best suit you. But whenever you give an invalid answer e.g. uncapitalized. It won't give you the points and goes to the next question. But I want it to give the same question again until a correct answer is given. Is this possible? It's pretty sad but I am forced to use the for loop to keep giving the question, otherwise I would have done it differently. Code:
import time
def vragen_ophalen():
with open("C:\\Users\digit\PycharmProjects\pythonProject2\TXT\meerkeuzevragen.txt", "r") as fh:
all_lines = fh.read()
return all_lines;
def vraag_en_antwoord(q_a):
se = 0 # Points for Software Engineer
bdam = 0 # Points for Business DataManagement
interactie = 0 # Points for Interaction Technology
fict = 0 # Points for CSI ICT
antwoorden = " " # All Answers together for writing data
vraagenantwoorden = "" # All answers including Question No.
vraagnummer = 1 # Question No.
for line in q_a.split('#'):
print(line)
antwoord = input("Kies uit A, B, C of D: \n")
if antwoord == "A": # If the input given == "A" 1 point will be added to SE
se = se + 1
elif antwoord == "B": # If the input given == "B" 1 point will be added to BDAM
bdam = bdam + 1
elif antwoord == "C": # If the input given == "C" 1 point wil be added to Interaction Technology
interactie = interactie + 1
elif antwoord == "D": # If the input given == "D" 1 point will be added to CSI ICT
fict = fict + 1
else:
print("Antwoord niet mogelijk. Let op Hoofdletters!") # Answer Not possible
vraagenantwoord = f"{vraagnummer}. {antwoord}" # Combining Question No. With answer
vraagnummer = vraagnummer + 1 # Adding 1 to Question No. For next question
vraagenantwoorden = f"{vraagenantwoorden} \n {vraagenantwoord}" # Adds alls question and their Quesiton No. together
with open("TXT\\antwoorden_gebruiker.txt", "w") as fd:
fd.write(vraagenantwoorden) # Writes all Answer and Question No. to TXT file
main()
def main():
run = input("Kies 1 voor Vragenlijst \n Kies 2 voor resultaten \n Kies q voor afsluiten \n")
if run == "1":
vraag = vragen_ophalen()
vraag_en_antwoord(vraag)
elif run == "2":
with open("TXT\\antwoorden_gebruiker.txt", "r") as fr:
print(fr.read())
elif run == "q":
exit()
else:
print("Onbekend Commando.")
print("Herstarten in 5 seconden")
time.sleep(5)
main()
if __name__ == '__main__':
main()
Aucun commentaire:
Enregistrer un commentaire