Lesson 5.3 · Write it
Same word
A functionPython or Java14 tests, 11 of them hidden
On a phone? Put the lines in order instead
Write a function that returns whether two words are the same when upper and lower case are ignored.
- Each word contains only English letters, and has at least one letter.
- Two words are the same when they have the same letters in the same order. The case of each letter does not matter.
- Return
TrueorFalse(trueorfalsein Java).
Only the value your function returns is checked.
def same_word(first: str, second: str) -> bool
Examples
Your function is tested on 14 cases: the 3 examples below, and 11 hidden ones that check the rules above.
- same_word("Quit", "qUIT") should return True: the same letters, with capitals in different places (rule 2)
- same_word("plays", "play") should return False: different words, the second is the start of the first (rule 2)
- same_word("go", "goes") should return False: different words, the first is the start of the second (rule 2)
public static boolean sameWord(String first, String second)
Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.Checking whether Java answers can run here.
Examples
Your function is tested on 14 cases: the 3 examples below, and 11 hidden ones that check the rules above.
- sameWord("Quit", "qUIT") should return true: the same letters, with capitals in different places (rule 2)
- sameWord("plays", "play") should return false: different words, the second is the start of the first (rule 2)
- sameWord("go", "goes") should return false: different words, the first is the start of the second (rule 2)