"type object 'Question' has no attribute 'frag' " wird mir als Fehlercode angezeigt... was hab ich falsch gemacht?
Verfasst: Samstag 23. März 2019, 11:51
#Das ist mein Code
from Fragen import Question
fragen_liste = [
"Welche Farbe haben Äpfel?\n(a) Rot/Grün\n(b) Blau/Gelb\n(c) Grau\n\n",
"Welche Farbe haben Bananen?\n(a) Rot\n(b) Orange\n(c) Gelb\n\n",
"Welche Farbe haben Karotten?\n(a) Blau\n(b) Orange\n(c) Violett\n\n"
]
Array = [
Question(fragen_liste[0], "a"),
Question(fragen_liste[1], "c"),
Question(fragen_liste[2], "b")
]
def test(Fra):
score = 0
for f in Fra:
antw = input(Question.frag)
if antw == Question.antwort:
score += 1
print("Du hast " + str(score) + "/" + str(len(Fra)) + "richtig")
test(Array)
#Und das ist aus der Datei "Fragen"
class Question:
def __init__(self, frag, antwort):
self.frag = frag
self.antwort = antwort
#Ich verstehe nicht so ganz, wo mein Fehler liegt. Sieht genauso aus, wie bei anderen
from Fragen import Question
fragen_liste = [
"Welche Farbe haben Äpfel?\n(a) Rot/Grün\n(b) Blau/Gelb\n(c) Grau\n\n",
"Welche Farbe haben Bananen?\n(a) Rot\n(b) Orange\n(c) Gelb\n\n",
"Welche Farbe haben Karotten?\n(a) Blau\n(b) Orange\n(c) Violett\n\n"
]
Array = [
Question(fragen_liste[0], "a"),
Question(fragen_liste[1], "c"),
Question(fragen_liste[2], "b")
]
def test(Fra):
score = 0
for f in Fra:
antw = input(Question.frag)
if antw == Question.antwort:
score += 1
print("Du hast " + str(score) + "/" + str(len(Fra)) + "richtig")
test(Array)
#Und das ist aus der Datei "Fragen"
class Question:
def __init__(self, frag, antwort):
self.frag = frag
self.antwort = antwort
#Ich verstehe nicht so ganz, wo mein Fehler liegt. Sieht genauso aus, wie bei anderen