Config Router

  • Google Sheets
  • CCNA Online training
    • CCNA
  • CISCO Lab Guides
    • CCNA Security Lab Manual With Solutions
    • CCNP Route Lab Manual with Solutions
    • CCNP Switch Lab Manual with Solutions
  • Juniper
  • Linux
  • DevOps Tutorials
  • Python Array
You are here: Home / Converting a sentence to piglatin in Python [duplicate]

Converting a sentence to piglatin in Python [duplicate]

August 23, 2021 by James Palmer

Here is the code:
def main():
lst = [‘sh’, ‘gl’, ‘ch’, ‘ph’, ‘tr’, ‘br’, ‘fr’, ‘bl’, ‘gr’, ‘st’, ‘sl’, ‘cl’, ‘pl’, ‘fl’]
sentence = input(‘Type what you would like translated into pig-latin and press ENTER: ‘)
sentence = sentence.split()
for k in range(len(sentence)):
i = sentence[k]
if i[0] in [‘a’, ‘e’, ‘i’, ‘o’, ‘u’]:
sentence[k] = i+’ay’
elif t(i) in lst:
sentence[k] = i[2:]+i[:2]+’ay’
elif i.isalpha() == False:
sentence[k] = i
else:
sentence[k] = i[1:]+i[0]+’ay’
return ‘ ‘.join(sentence)

def t(str):
return str[0]+str[1]

if __name__ == “__main__”:
x = main()
print(x)

Runs as:
bash-3.2$ python3 pig.py
Type what you would like translated into pig-latin and press ENTER: my gloves are warm
ymay ovesglay areay armway
bash-3.2$

This code uses the logic found here.

Here is a quick one
def main():
words = str(input(“Input Sentence:”)).split()
for word in words:
print(word[1:] + word[0] + “ay”, end = ” “)
print ()

main()

A better solution would probably use list comprehension so you could actually use the output, but this does what you asked.
EDIT:
This works for python3.x
If you want it to work for python2 you are going to have a bit more fun. Just add the strings together for each word, then print the result string.

Related

Filed Under: Uncategorized

Recent Posts

  • How do I give user access to Jenkins?
  • What is docker volume command?
  • What is the date format in Unix?
  • What is the difference between ARG and ENV Docker?
  • What is rsync command Linux?
  • How to Add Music to Snapchat 2021 Android? | How to Search, Add, Share Songs on Snapchat Story?
  • How to Enable Snapchat Notifications for Android & iPhone? | Steps to Turn on Snapchat Bitmoji Notification
  • Easy Methods to Fix Snapchat Camera Not Working Black Screen Issue | Reasons & Troubleshooting Tips to Solve Snapchat Camera Problems
  • Detailed Procedure for How to Update Snapchat on iOS 14 for Free
  • What is Snapchat Spotlight Feature? How to Make a Spotlight on Snapchat?
  • Snapchat Hack Tutorial 2021: Can I hack a Snapchat Account without them knowing?

Copyright © 2025 · News Pro Theme on Genesis Framework · WordPress · Log in