Using JES/Jython
Function Name: sortMusic()
Parameters: Name -string of artist’s name
Write a function that finds the first letter of an artist’s name.
Test Cases:
>>>sortMusic(“Lizzo”)
Lizzo starts with the letter L.
>>>sortMusic(“Khalid”)
Khalid starts with the letter K.
Here is the completed code for this problem. Given the test cases and function description, I’m assuming there is nothing more complex in this method. If this is not what you’re looking for, let me know. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
#code
#required method. assuming name always contain at
least
#one letter, or else, IndexError will be raised
def sortMusic(name):
#getting first letter of the name
firstLetter=name[0]
#printing name and first letter
print "%s starts with the letter
%s." % (name,firstLetter)
#testing the method, ignore if you are testing method from
terminal window
sortMusic('Khalid') #will print "Khalid starts
with the letter K."
sortMusic('Lizzo') #will print "Lizzo starts
with the letter L."
#output
Khalid starts with the letter K.
Lizzo starts with the letter L.
Get Answers For Free
Most questions answered within 1 hours.