Compare Strings
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.
Example
Test Code | Output |
---|---|
print(compare('Hi', 'Hi'))
|
True
|
print(compare('Hi', 'hi'))
|
True
|
print(compare('hi', 'Hi'))
|
True
|
print(compare(' hi', 'hi'))
|
True
|
print(compare('hi', ' hi'))
|
True
|
print(compare('hi.', 'hi!'))
|
False
|
Swap Words
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.
Example
Test Code | Output |
---|---|
print(swap_words('hello world'))
|
world hello
|
print(swap_words('world hello'))
|
hello world
|
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:
- 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 program that prompts the user to enter a word and prints the specified word in Pig Latin.
Example
Enter a word: scram scram in Pig Latin is: am'scray Enter a word: immediate immediate in Pig Latin is: immediateyay
Hint
Submission
Please show your source code and run your programs for the instructor or lab assistant. Only programs that have perfect functionality will be accepted as complete.