Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. # Daniel Awerbuck
  2. # ITP115, Fall 2019
  3. # Lab 4
  4. # dawerbuc@usc.edu
  5.  
  6. import random
  7.  
  8. def function(word):
  9.     translatedString = word[1:] + word[0]
  10.     translatedString = translatedString.replace('k','c')
  11.     if len(word) >= 4:
  12.         translatedString = translatedString + getRandomVowel() + getRandomVowel() #add two vowels if word over 3 letters
  13.     elif len(word) <= 3: #add en if word less than 4 letters
  14.         translatedString += "en"
  15.     elif translatedString[-1] == "e":
  16.         translatedString = translatedString[:len(translatedString) - 1] + "ë" #replace last letter e with ë
  17.     if translatedString[0].upper() == True:
  18.         translatedString == translatedString.lower()
  19.         translatedString[0] == translatedString[0].upper()
  20.     return translatedString
  21.  
  22. def getRandomVowel(): #function returns a random vowel from the list aeiou, easy to implement into the translate function
  23.     vowellist = "aeiou"
  24.     vowels = random.randint(0, 4) #
  25.     return vowellist[vowels]
  26.  
  27.  
  28. print("Elcómewó óten heten Igpén Lvísheá ránslátórtë!\n(Welcome to the Pig Elvish translator!)")
  29. continueProgram = True
  30. while continueProgram:
  31.     ogword = input("Please enter a word to translate: ")
  32.     translated = function(ogword)
  33.     print("'" + ogword + "' in elvish is: " + translated)
  34.     cont = input("Would you like to enter another word?(y/n): ")
  35.     if cont.lower() == "n":
  36.         continueProgram = False
  37.         print("Oodbyega! Aveha aen icenë ayden!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement