Mir war Yaml am anfang zu schwer, also hab ich mich für normale Textdateien entschieden, das kann ich später noch ändern.
Die wordlist.txt ist in diesem Schema geschrieben:
Text;Text;Text#Übersetzung;Übersetzung;Übersetzung
Zurzeit wird nur ein deutsches Wort und mehrere Übersetzungen unterstützt, das kann man später leicht ändern. Jetzt ist mir aber erstmal wichtiger das es überhaupt Funktioniert.
Ich wollte zu dem normalen Vokabel abfragen noch ein kleines Ranking erstellen um die Wörter die man nicht so gut kann öfter abzufragen als die restlichen.
Also wollte ich das ganze in einer Textdatei abspeichern...Alles schön und gut, aber dann umsetzen ist etwas schwieriger...
Ich wollte bei jedem Falschen Wort eine Reihe von Aufgaben durchgehen, die die Übersetzung des Wortes in eine Liste einträgt und diese Liste dann abspeichert. Erst wenn das geschafft ist wollte ich mit dem Zusammenzählen der Punkte beginnen...
Zu Übungszwecken habe ich das ganze gleich in eine Klasse gepackt, aber genau dort liegt der Fehler.
Hier der Quellcode, wie er bis jetzt ausschaut:
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: UTF-8 -*-
#read line for line from a .txt file and ask for a words translation.
import random
class ranking(object):
def __init__(self):
object.__init__(self)
self.data = []
def add_false(begr):
data.append(points,begr) #Hinzufügen der Falschen Wörter
def save_ranking():#Falsche Wörter speichern
f = open("false.txt","aU")
f.write(self.data)
f.close()
def ask_voc():
'''
Read the file in a list, search one entry, ask it.
'''
rank = ranking()
f = open("wordlist.txt", "r") #open the wordlist
inh = f.readlines() #write the lines from wordlist down
f.close #close wordlist
now = random.choice(inh)#Search a random line from the wordlist
words, translations = now.split('#')#Split the line in words and their translations
translations = translations.rstrip("\n") #Remove the n on the end of the line
#For debugging: add following line, print words;print translations
word = words.split(';')#Split the words in singles.
translation = translations.split(';')#Split the translations in singles.
print "übersetzung für:"; print word#ask the translation from word
answ = raw_input('Antwort:')#get the answere
print "#" * 20#Print a little line
if answ in translation:
print "right"
print "+" * 20#Print a little line
else:
print "false"
print "answer:" + answ#Print the answere
print "translation:" ; print translation#Print the needed translation
rank.add_false("1",translation)
print "-" * 20#Print a little line
safe_ranking()
ask_voc()
TypeError: add_false() takes exactly 1 argument (3 given)
Welche Argumente geb ich ihm denn?? Also so wie ich das sehe gebe ich im Zwei (1 und Übersetzung). Und er verlang doch auch zwei??
[/python][/url]