Advertisement
Guest User

Untitled

a guest
Feb 28th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.94 KB | None | 0 0
  1. import sys
  2. import random
  3.  
  4. # I don't know any German, but I know a little Spanish so I went that route
  5. english_to_spanish = {"hello": "hola", "thing": "cosa", "dog": "perro",
  6.         "cat": "gato", "big": "grande", "telephone": "telefono",
  7.         "beer": "cerveza", "more": "mas", "fat": "gordo"}
  8.  
  9. option = raw_input("Choose <E>nglish to Spanish or <S>panish to English:")                 
  10. num_of_words = int(raw_input("How many words do you want to translate?"))
  11. correct_answers = 0.0  # making this a float allows the percentage calculation at end of script
  12. missed_answers = []
  13.  
  14. if num_of_words > len(english_to_spanish):      # if you're going to have 1000 words you can
  15.     print "I don't even know that many words!"  # probably get rid of this if block
  16.     sys.exit()
  17.  
  18. if option.lower() == "e":
  19.     word_list = random.sample(english_to_spanish, num_of_words)
  20.     for word in word_list:
  21.         print "\nEnglish: " + word
  22.         answer = raw_input("Enter the Spanish translation:")
  23.         if answer.lower() == english_to_spanish[word]:
  24.             print "That's right!"
  25.             correct_answers += 1
  26.         else:
  27.             print "Sorry, that's not right."
  28.             missed_answers.append(english_to_spanish[word])
  29.    
  30. elif option.lower() == "s":
  31.     span_words = random.sample(english_to_spanish, num_of_words)
  32.     for word in span_words:
  33.         print "\nSpanish:" + english_to_spanish[word]
  34.         answer = raw_input("Enter the English translation:")
  35.         if answer.lower() == word:
  36.             print "You got it!"
  37.             correct_answers += 1
  38.         else:
  39.             print "Oops. That's not right."
  40.             missed_answers.append(word)
  41. else:
  42.     print "I don't understand that."
  43.     sys.exit()
  44.    
  45. percentage = (correct_answers / num_of_words) * 100
  46. print "You got %d out of %d words right! That's %d percent!" % \
  47.     (correct_answers, num_of_words, percentage)
  48. print "You missed these words: "
  49. for miss in missed_answers:
  50.     print miss,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement