Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import random
- # I don't know any German, but I know a little Spanish so I went that route
- english_to_spanish = {"hello": "hola", "thing": "cosa", "dog": "perro",
- "cat": "gato", "big": "grande", "telephone": "telefono",
- "beer": "cerveza", "more": "mas", "fat": "gordo"}
- option = raw_input("Choose <E>nglish to Spanish or <S>panish to English:")
- num_of_words = int(raw_input("How many words do you want to translate?"))
- correct_answers = 0.0 # making this a float allows the percentage calculation at end of script
- missed_answers = []
- if num_of_words > len(english_to_spanish): # if you're going to have 1000 words you can
- print "I don't even know that many words!" # probably get rid of this if block
- sys.exit()
- if option.lower() == "e":
- word_list = random.sample(english_to_spanish, num_of_words)
- for word in word_list:
- print "\nEnglish: " + word
- answer = raw_input("Enter the Spanish translation:")
- if answer.lower() == english_to_spanish[word]:
- print "That's right!"
- correct_answers += 1
- else:
- print "Sorry, that's not right."
- missed_answers.append(english_to_spanish[word])
- elif option.lower() == "s":
- span_words = random.sample(english_to_spanish, num_of_words)
- for word in span_words:
- print "\nSpanish:" + english_to_spanish[word]
- answer = raw_input("Enter the English translation:")
- if answer.lower() == word:
- print "You got it!"
- correct_answers += 1
- else:
- print "Oops. That's not right."
- missed_answers.append(word)
- else:
- print "I don't understand that."
- sys.exit()
- percentage = (correct_answers / num_of_words) * 100
- print "You got %d out of %d words right! That's %d percent!" % \
- (correct_answers, num_of_words, percentage)
- print "You missed these words: "
- for miss in missed_answers:
- print miss,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement