CPSC120A
Fundamentals of Computer Science I

Lab 20

String Methods

Practice 1

Write a function called compare(string1, string2), which takes two strings as parameters. The function should return True if the two strings are the same, ignoring capitalization and ignoring leading and trailing whitespace, and False otherwise.


Practice 2

Write a function called swap_words(string), which takes a single string as a parameter. Assume that the specified string contains two words separated by exactly one space character. The function should return a new string that swaps the positions of the two words in the specified string.


Pig Latin Translator

Pig Latin is a somewhat silly language parody that is actually entirely English based. It is a simple transposition of letters that gives the effect of a "foreign" sounding language. However, even Thomas Jefferson couldn't resist writing letters to his friends in Pig Latin. The rules for converting an English word to Pig Latin are incredibly easy:

Details

Write a function called convert_to_pig_latin(text) in a file called pig_latin.py. This function takes a string as a parameter, and returns a string which is the pig latin translation of the text parameter.

Make sure your program handles all necessary cases gracefully. What additional test cases should you check?

Sample Test Cases

Function Parameters Expected Output
"scram" am'scray
"immediate" immediateyay

Hint

Challenge

Ofyay ourse'cay, ityay akes'may ittle'lay ense'say o'tay ite'wray ayay ogram'pray o'tay anslate'tray ayay ord'way o'tay ig'pay atin'lay ifyay ityay annot'cay anslate'tray ack'bay e'thay otheryay ay'way! Ite'wray ayay unction'fay onvert_from_pig_latin'cay at'thay akes'tay ayay ord'way alreadyyay inyay ig'pay atin'lay, andyay eturns'ray e'thay Englishyay equivalentyay.

Submission

Please show your source code and run your programs for the instructor or lab assistant. Only a programs that have perfect style and flawless functionality will be accepted as complete.