Advertisement
Python253

ipp1_1_piglatin

May 31st, 2024
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Filename: ipp1_1_piglatin.py
  4. # Version: 1.0.0
  5. # Author: Jeoi Reqi
  6.  
  7. """
  8. Description:
  9.    - This script implements "Chapter 1: Practice Project #1 - Pig Latin" from the book "Impractical Python Projects" by Lee Vaughan.
  10.    = It translates words into Pig Latin based on certain rules:
  11.        - If a word starts with a vowel, 'way' is appended to the end.
  12.        - If a word starts with a consonant, the consonant is moved to the end of the word and 'ay' is appended.
  13.  
  14. Requirements:
  15.    - Python 3.x
  16.    - sys module
  17.  
  18. Usage:
  19.    - Run the script and follow the prompts to enter a word.
  20.    - The script will provide the Pig Latin translation of the entered word.
  21.    - You can continue translating words by typing '1' to try again or '0' to stop the script.
  22.  
  23. Additional Notes:
  24.    - This script assumes that input words consist only of lowercase letters.
  25.    - The translation rules are based on a basic implementation of Pig Latin and may not cover all possible cases.
  26. """
  27.  
  28. import sys
  29.  
  30. VOWELS = 'aeiouy'
  31.  
  32. while True:
  33.     word = input("Type a word and get its Pig Latin translation: ")
  34.  
  35.     if word[0] in VOWELS:
  36.         pig_latin = word + 'way'
  37.     else:
  38.         pig_latin = word[1:] + word[0] + 'ay'
  39.  
  40.     print(f"Pig Latin translation: {pig_latin}")
  41.  
  42.     try_again = input("\n\nTry again? (Press 1 to continue or 0 to stop)\n ")
  43.     if try_again == "0":
  44.         sys.exit()
  45.  
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement