-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvocabularytraining_learngerman.py
237 lines (197 loc) · 9.48 KB
/
vocabularytraining_learngerman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# -*- coding: utf-8 -*-
#vocabulary training for translating English to german
#by Miriam Kümmel
from collections import defaultdict
import operator
#dictionaries the exercises are based on:
farmDict = {"cat": "Katze", "to work": "arbeiten", "pig": "Schwein", "cow": "Kuh", "barn": "Stall", "farmer": "Bauer", "calf": "Kalb",
"egg": "Ei", "chicken": "Huhn", "shovel": "Schaufel", "dog": "Hund", "tractor": "Traktor"}
schoolDict = {"blackboard": "Tafel", "chalk": "Kreide", "chair": "Stuhl", "clock": "Uhr", "teacher": "Lehrer",
"to learn": "lernen", "break": "Pause", "language": "Sprache", "to calculate": "rechnen",
"to write": "schreiben"}
bodyDict = {"nose": "Nase", "face": "Gesicht", "muscle": "Muskel", "hair": "Haare", "healthy": "gesund", "strong": "stark",
"bone": "Knochen", "power": "Kraft", "to dance": "tanzen", "leg": "Bein", "heart": "Herz", "to run": "rennen",
"to shave": "rasieren"}
holidayDict = {"sand": "Sand", "to fly": "fliegen", "beach": "Strand", "to swim": "schwimmen", "sun": "Sonne", "family": "Familie",
"book": "Buch", "ocean": "Meer", "sunburn": "Sonnenbrand", "hotel": "Hotel", "to hike": "wandern", "mountain": "Berg",
"to relax": "entspannen", "to play": "spielen"}
dicts = ["Farm", "School", "Body", "Holidays"]
#dicitionaries for wrong answers
tryAgainFarm = {}
tryAgainSchool = {}
tryAgainBody = {}
tryAgainHoliday = {}
global stars #global variable
stars = 0
schluss = False #will only be true if the user wants to leave the program
#welcome
print "\n\nWelcome, little dwarf! \nYou want to be the best in german vocabularies? Let us carry you off into the forests of vocabularies...once you made it through, you will be a wiser creature. Please choose:"
while not schluss:
choice = raw_input( #user has several possibilities to start the program
"""
Wander an unknown forest - press "1"
Leave the world of vocabularies - press "2"
Make up for your mistakes - press "3"
See what level you are - press "4"
Add a new mystery to the forest - press "5"
""")
#Choice 1: Exercise
if choice == "1":
#description
print "\n\nWander around in the forests of vocabularies and collect a star whenever you solve a mystery by typing in the right translation of a word. The more stars you are gathering, the more you will develop! You did a wrong guess? Don't worry, you can make up for your mistakes later on..."
print "Starting off, you are still a dwarf, but if you learn, study, absorb the wisdom...some day you might be the Lord of the Vocabularies..."
print "Have an adventurous journey..."
#checks if choice is in dicitionaries
print "\nThese are the forests:", dicts
dictsChoice = raw_input ("Which one would you like to wander? ")
if dictsChoice in dicts:
print "\nYou will wander around in this forest of vocabularies:", dictsChoice, "! Please consider capitalization. Good luck!"
else:
print "\nThere is no forest called like this. Try again, brave wanderer."
################## Function for the exercise ##################
def abfrage(welchesDict, welchesTryAgain):
global stars
for i in welchesDict.keys():#iterates dictionary
done = False #done only if translation is correct
while not done:
print "\nEnglish word:", i
uebers = raw_input("German translation: ")
if uebers == welchesDict[i]: #is it correct?
print "That's correct!"
stars += 1 #more points
done = True
else:
print "Sorry, not correct!",
print "Here is a hint:", str(welchesDict[i])[0:1], "..." #hint is first letter of translation
uebers = raw_input("German translation: ") #nächster Versuch
if uebers != welchesDict[i]:
print "Here is another hint:", str(welchesDict[i])[0:3], "..." #another hint
help = raw_input("Press x to get the complete word, press Enter if you can solve the mystery now.")
if help == "x": #shows whole word
print "This is the correct translation:", welchesDict.get(i), ". Type it in again!"
else:
print "Now the translation is correct!"
done = True
#wrong translation will be added to tryAgain so the user can try again in Choice 3
welchesTryAgain[i] = welchesDict[i]
stars -= 1 #less points
print "You've gathered", stars, "star(s)!" #end: all the points gathered will be shown
if stars <= float((len(welchesDict)*0.5)):
print "\nYou can do better!"
if stars <= float((len(welchesDict)*0.7)):
print "\nKeep it up!"
if stars > float((len(welchesDict)*0.9)):
print "\nGreat!"
##############################################################
#Anwendung der Funktion je nach Dictionary
if dictsChoice == "Farm":
abfrage(farmDict, tryAgainFarm)
if dictsChoice == "School":
abfrage(schoolDict, tryAgainSchool)
if dictsChoice == "Body":
abfrage(bodyDict, tryAgainBody)
if dictsChoice == "Holidays":
abfrage(holidayDict, tryAgainHoliday)
#Choice 2: leave the program
if choice == "2":
if stars < 10:
print "You should come back soon. You only gathered", stars, "stars today!"
else:
print "Thank you for your brave journey. You've gathered", stars, "stars today!"
schluss = True
#Choice 3: do wrong translations again
if choice == "3":
if tryAgainFarm == {} and tryAgainSchool == {} and tryAgainBody == {} and tryAgainHoliday == {}:
print "You haven't made any mistakes."
else:
#right translation gives the user 0.5 points now
print "You want to make up for your mistakes. Laudable! Remember that every right guess now brings you 0.5 stars."
#in which dictionary?
newGuess = raw_input("\nIn which forest did you make mistakes? Farm, School, Body or Holidays? ")
#######function for formerly wrong answers##########
def redo(welchesTryAgain, welchesDict):
global stars
if welchesTryAgain != {}: #if there have been wrong answers the user can try again
#iterates wrong answers
for k in welchesTryAgain.keys():
done = False
while not done:
print "\nGerman word:", k
uebers = raw_input("Your translation: ")
if uebers == welchesTryAgain[k]:
print "Now your translation is correct!"
welchesTryAgain.remove(k) #remove
stars += 0.5
done = True
else:
#if the translation is wrong again, show correct answer
print "Sorry, still not correct! This is the correct translation:", welchesDict.get(k)
welchesTryAgain[i] = welchesDict.get(k)
stars -= 1
print "You've gathered", stars, "star(s) now!" #show points
else: #if there is nothing done wrong, you can't try again
print "\nNo mistakes have been made here."
######################################################################
#depending on user choice: which dictionary will be accessed
if newGuess == "Farm":
redo(tryAgainFarm, farmDict)
if newGuess == "School":
redo(tryAgainSchool, schoolDict)
if newGuess == "Body":
redo(tryAgainBody, bodyDict)
if newGuess == "Holidays":
redo(tryAgainHoliday, holidayDict)
if newGuess not in dicts:
print "\nThere is no forest named", newGuess, "."
#Choice 4: show points and level
if choice == "4":
print "You've gathered", stars, "star(s) so far."
#Levels:
if stars <= 10:
print "You are still a dwarf! Keep it up!"
if stars >10 and stars <=15:
print "You are a goblin already! Keep it up!"
if stars >15 and stars <=20:
print "Now you are a fairy! Keep it up!"
if stars >20 and stars <=25:
print "Wow! You are an elf! Keep it up!"
if stars >25 and stars <=30:
print "You can be proud! You are a sorcerer! Keep it up!"
if stars >30:
print "Wow! You've made it! You are the Lord of the Vocabularies!"
#Choice 5: add new word pair to dictionary
if choice == "5":
#user can only do this if he/she gathered enough points
if stars < 21:
print "Sorry, you are not trustworthy enough yet! Learn and gain some wisdom..."
print "as soon as you have evolved to an elf we will welcome you here again...You still lack", (21-stars), "stars."
else:
print "You wish to share your wisdom? There you go..."
print "To which forest do you want to add a mystery?", dicts
newWords = raw_input("Choose: ")
######### function for adding new word pairs ##########################
def newWord(whichDict):
add = False #only true if user wants to leave
while add == False:
neueUeb = raw_input("Put in the english word: ")
#if the word is there already it is not possible to add it again
if neueUeb in whichDict.keys():
print "This mystery is in this forest already."
break
englUeb = raw_input("Put in the german translation: ")
whichDict[neueUeb] = englUeb #adds translation to key
print "\n","Thank you. Your mystery", neueUeb, "has been added to the forest", newWords,":\n", whichDict, "."
#does the user want to add more?
more = raw_input("Do you want to put in more words? Press 'y' or 'n' ")
if more == "n":
add = True
###########################################################################
#use function depending on input
if newWords == "Farm":
newWord(farmDict)
if newWords == "School":
newWord(schoolDict)
if newWords == "Body":
newWord(bodyDict)
if newWords == "Holidays":
newWord(holidayDict)