Hello!
Today's question is this!
Check if the given string consists of only letters and spaces and if every letter is in lower case.
Examples
letters_only("PYTHON") ➞ False letters_only("python") ➞ True letters_only("12321313") ➞ False letters_only("i have spaces") ➞ True letters_only("i have numbers(1-10)") ➞ False letters_only("") ➞ False
From : Letters Only // Edabit
The code is here.
Let's see one by one.
First, let's think about the first if.
If the first if is gone, when a parameter came, it will be True.
letters_only("")
It has 0 letters so it does not loop.
So, it finishes the loop and returns True.
It should be False.
So, we need to check if the parameter(s) has no letters(or numbers).
If then, return False.
Next, we will go into the loop.
Let's see if all letters are all lower case and has no numbers.
When one letter is upper or has number(numeric), we will return False.
After finishing the loop, we will return True.
0 件のコメント:
コメントを投稿