Search code, repositories, users, issues, pull requests...
We read every piece of feedback, and take your input very seriously.
Use saved searches to filter your results more quickly.
To see all available qualifiers, see our documentation .
CECS 475 lab assignment 3
Name already in use.
Use Git or checkout with SVN using the web URL.
Work fast with our official CLI. Learn more about the CLI .
- Open with GitHub Desktop
- Download ZIP
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Lab-assignment-3, contributors 2.
LAB ASSIGNMENT 3
Embed on website
- Toggle navigation
- Portfolio Profile
- Lab Assignment #1
- Lab Assignment #2
Lab Assignment #3
- Lab Assignment #4
- Lab Assignment #5
- Lab Assignment #6
- Lab Assignment #7
- Lab Assignment #8
Description In this assignment, I will follow the steps on how to build a Pig Latin translator from Codecademy’s Python section. Pig Latin is a pseudo-language that is used by English-speakers who wants to disguise their words from non-Pig Latin speakers. The rule is to take the first consonant of an English word, move it to the end of the word and use the suffixes ‘ay’. If the word begins with a vowel, add ‘way’ at the end. For example, Pig becomes igpay, banana becomes ananabay, and aardvark becomes aardvarkway. Below are the instructions I followed in Codecademy.
Break It Down 1. Ask the user to input a word in English. 2. make sure the user entered a valid word. 3. Convert the word from English to Pig Latin. 4. Display the translation result.
Ahoy! (Or Should I Say Ahoyay!) Print the phrase “Pig Latin” on the screen.
Input! 1. On line 4, use raw_input(“enter a word:”) to ask the user to enter a word. Save the results of raw_input() in a variable called original. 2. Click save & submit code. 3. Type a word in the console window and press enter.
Check Yourself! 1. Add an if statement that checks that len(original) is greater than zero. Don’t forget the : at the end of the if statement! 2. If the string actually has some characters in it, print the user’s word. 3. Otherwise (i.e. an else: statement), print “empty”.
Check Yourself… Some More Use and to add a second condition to your if statement. In addition to your existing check that the string contains characters, you should also use .isalpha() to make sure that it only contains letters. Don’t forget to keep the colon at the end of the if statement.
Pop Quiz! Take some time to test your current code. Try some inputs that should pass and that should fail. Enter some strings that contain non-alphabetical characters and an empty string.
Ay B C Create a variable named pyg and set it equal to the suffix ‘ay’.
Word Up Inside your if statement: 1. Create a new variable called word that holds the .lower()-case conversion of original. 2. Create a new variable called first that holds word, the first letter of word.
Move It On Back On a new line after where you created the first variable: Create a new variable called new_word and set it equal to the concatenation of word, first, and pyg.
Ending Up Set new_word equal to the slice from the first index all the way to the end of new_word. Use [1:len(new_word)] to do this.
Testing, Testing, Is This Thing On?
CODE pyg = ‘ay’ original = raw_input(‘Enter a word: ‘) word = original.lower() first = word new_word = word + first + pyg new_word = new_word[1:len(new_word)] if len(original) > 0 and original.isalpha(): print new_word else: print ’empty’
- Write a brief paragraph to introduce yourself to your visitors and explain what they will find on this site. Be sure to add more developed content to your About Me page. (Edit this paragraph in Dashboard > Widgets > Text)
- Search for:
Learning Blog Archives
Recent posts, the openlab at city tech: a place to learn, work, and share.
The OpenLab is an open-source, digital platform designed to support teaching and learning at City Tech (New York City College of Technology), and to promote student and faculty engagement in the intellectual and social life of the college community.
New York City College of Technology | City University of New York
Our goal is to make the OpenLab accessible for all users.
Learn more about accessibility on the OpenLab
- - Attribution
- - NonCommercial
- - ShareAlike
© New York City College of Technology | City University of New York