ignor und upload flasK
This commit is contained in:
1 parent
294a15cb8e
commit
e9a1261423
8 files changed
+120
-5
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import csv # CSV handling
|
||||
import random
|
||||
import os
|
||||
|
||||
#file = "C:/Users/bruno/Documents/__CODING__/0-git (Group)/robotik-wise23/robo/fragen1.csv"
|
||||
#file = os.getcwd() + "fragen1.csv"
|
||||
#file = os.path.join(os.getcwd(), "robo", "fragen1.csv") # Windows Entwicklung
|
||||
file = os.path.join(os.getcwd(), "fragen1.csv") # Raspi
|
||||
|
||||
#with open(file, newline="", encoding="utf-8") as csvfile: #
|
||||
with open(file, newline="", encoding="cp1252") as csvfile: # Code wird als Excel Windows-1252 Input CSV gelesen
|
||||
database = csv.reader(csvfile, delimiter=";") # Validating the "csvfile" into "database" with the delimiter "," (Comma Seperated Values)
|
||||
|
||||
q_a = [] # Empty list for all questions and answers
|
||||
|
||||
for row in database: # alle Zeilen in der Datenbank durchlaufen
|
||||
index = int(row[0]) # Laufende Nummer
|
||||
question = str(row[1]) # Frage (ist der erste Teil)
|
||||
answer = str(row[2]) # Antwort (3. Spalte in der CSV Datenbank)
|
||||
q_a.append({"index": index,"question": question, "answer": answer}) # Eine Liste bauen
|
||||
|
||||
# for i in q_a: # For every element in "q_a"
|
||||
# print("[" + str(i["index"]) + "] Frage: " + i["question"] + "\n[" + str(i["index"]) + "] Antwort: " + i["answer"] + "\n") # Print "question", "answer" and "index" for current element
|
||||
|
||||
|
||||
while True:
|
||||
# Zufällig eine Frage auswählen
|
||||
zufallige_frage = random.choice(q_a)
|
||||
ID = zufallige_frage["index"]
|
||||
frage = zufallige_frage["question"]
|
||||
antwort = zufallige_frage["answer"]
|
||||
|
||||
#print(f"wir sind in {os.getcwd()}")
|
||||
|
||||
# Frage und Antwort ausgeben
|
||||
print(f"Frage:\t({ID})\t{frage}")
|
||||
# print(f"Antwort:\t{antwort}")
|
||||
|
||||
# Auf Eingabe warten
|
||||
# input("Drücke Enter für die nächste Frage...")
|
||||
DieAntwort= input(" > ")
|
||||
if ( DieAntwort == antwort ):
|
||||
print ("Sehr gut!")
|
||||
else :
|
||||
print ("Nein! Nochmal. (Setzen, 6) ")
|
||||
|
||||
|
||||
Reference in new issue
Block a user