나는 이렇게 학습한다/Algorithm & SQL

Are You Playing Banjo?

daco2020 2022. 5. 2. 23:36
반응형

Create a function which answers the question "Are you playing banjo?".
If your name starts with the letter "R" or lower case "r", you are playing banjo!

The function takes a name as its only argument, and returns one of the following strings:

name + " plays banjo" 
name + " does not play banjo"

Names given are always valid strings.

 

Solution:

1. Check if the first letter of 'name' is 'r'.
2. If it is 'r', make the sentence " plays banjo".
3. If it is not 'r', make a sentence "does not play banjo".
4. After name, the created sentence is attached and returned.

 

def are_you_playing_banjo(name):
    return name + (name[:1].lower() == "r" and " plays" or " does not play") + " banjo"

 

 

 

반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

Disemvowel Trolls  (0) 2022.05.05
Categorize New Member  (0) 2022.05.03
Find the vowels  (0) 2022.05.01
Odd or Even?  (0) 2022.04.30
Sort array by string length  (0) 2022.04.29