Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: ipp1_1_piglatin.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- - This script implements "Chapter 1: Practice Project #1 - Pig Latin" from the book "Impractical Python Projects" by Lee Vaughan.
- = It translates words into Pig Latin based on certain rules:
- - If a word starts with a vowel, 'way' is appended to the end.
- - If a word starts with a consonant, the consonant is moved to the end of the word and 'ay' is appended.
- Requirements:
- - Python 3.x
- - sys module
- Usage:
- - Run the script and follow the prompts to enter a word.
- - The script will provide the Pig Latin translation of the entered word.
- - You can continue translating words by typing '1' to try again or '0' to stop the script.
- Additional Notes:
- - This script assumes that input words consist only of lowercase letters.
- - The translation rules are based on a basic implementation of Pig Latin and may not cover all possible cases.
- """
- import sys
- VOWELS = 'aeiouy'
- while True:
- word = input("Type a word and get its Pig Latin translation: ")
- if word[0] in VOWELS:
- pig_latin = word + 'way'
- else:
- pig_latin = word[1:] + word[0] + 'ay'
- print(f"Pig Latin translation: {pig_latin}")
- try_again = input("\n\nTry again? (Press 1 to continue or 0 to stop)\n ")
- if try_again == "0":
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement