Question: For my class I have to build a python program that obeys these requirements: Instructions Pig Latin is a pseudo-dialect of English most used by

For my class I have to build a python program that obeys these requirements:

Instructions Pig Latin is a pseudo-dialect of English most used by children. It usually is spoken, but occasionally is written as well. There are several variations of rules for Pig Latin. The dialect that we will use follows these rules: 1. If a word begins with a consonant or consonant group, move the consonants to the end of the word and add ay. 2. If a word begins with a vowel or vowel group, leave the vowels in place and add yay to the end of the word. 3. Retain all capitalization, punctuation, and spacing. For example, maybe -> aybemay flood -> oodflay strangely -> angelystray able -> ableyay out -> outyay ought -> oughtyah Ooh! This, is an angry, Grand test! So, stretch. -> Oohyay! Isthay, isyay anyay angryyay, Andgray esttay! Osay, etchstray. Write a fruitful function called piglatin() that translates a single English word into Pig Latin following those rules using regular expressions to accomplish the work. Write a main driver that requests a file name from the user. It then translates the entire file into Pig Latin, displaying its results on the console.

-----------------------------------------------------------------------

I was able to build this program based of an earlier question I asked:

import re def piglatin(word): # Define vowels vowels = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'] # Check if the word starts with a vowel or vowel group if word[0] in vowels or (len(word) > 1 and word[:2].lower() in ['qu', 'tr', 'br', 'th', 'sh']): # Add 'yay' to the end of the word pig_latin_word = word + 'yay' else: # Find the consonant or consonant group at the beginning of the word consonants = set('abcdefghijklmnopqrstuvwxyz') - set(vowels) consonant_group = '' for i in range(len(word)): if word[i] in consonants: consonant_group += word[i] else: break # Move the consonant or consonant group to the end of the word and add 'ay' pig_latin_word = word[len(consonant_group):] + consonant_group + 'ay' return pig_latin_word # Prompt the user for a file name and open the file filename = input('Enter a file name: ') with open(filename, 'r') as file: # Read the file line by line and translate each line to Pig Latin for line in file: words = re.findall(r'\b\w+\b', line) pig_latin_line = '' for word in words: # Translate the word to Pig Latin and add it to the pig_latin_line pig_latin_word = piglatin(word) pig_latin_line += pig_latin_word + ' ' # Display the translated line on the console print(pig_latin_line) ----------------------------------------------------------------------------------

But now this program returns this error whenever I enter the name of a file:

Traceback (most recent call last): File "C:\Users\Gryphon8tr\PycharmProjects\pythonProject\chegy.py", line 28, in with open(filename, 'r') as file: FileNotFoundError: [Errno 2] No such file or directory: 'PigText1.txt' ------------------------------------------------------------------------------------------------------------------------------------

PigText1.txt is a real file that exists in my downloads folder (This is the file's path: "C:\Users\Gryphon8tr\Downloads\PigText1.txt").

How would the issue I'm having be resolved so the program will be able to convert text files into pig latin?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!