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 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:
- If the first character of the word is a vowel, append the string "yay" to the end.
- If the first character is a consonant, then all consonants up to (but not including) the first vowel are moved to the end of the word. A ' character is placed between the transposed characters. Then the string "ay" is appended to the word.
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
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.