Question

Using JES/Jython Function Name: sortMusic() Parameters: Name -string of artist’s name Write a function that finds...

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.

Homework Answers

Answer #1

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.
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Using JES/Jython Function Name: approachAllAngles() Parameters: Sides- integer of how many sides the shape has Using...
Using JES/Jython Function Name: approachAllAngles() Parameters: Sides- integer of how many sides the shape has Using the formula, D = ((Number of sides - 2) * 180) / Number of sides write a function that takes in the number of sides in your polygon and prints a sentence containing the angle measurements and the number of sides in the polygon. Test Cases: >>>approachAllAngles(4) Each angle in a regular polygon with 4 sides measures 90 degrees. >>>approachAllAngles(9) Each angle in a...
using python Write function stringCount() that takes two string inputs—a file name and a target string—...
using python Write function stringCount() that takes two string inputs—a file name and a target string— and returns the number of occurrences of the target string in the file. >>> stringCount('example.txt', 'line') 4
using the python Write a function oneSpaceAfterPeriod( String Parameter ) that will return a string with...
using the python Write a function oneSpaceAfterPeriod( String Parameter ) that will return a string with one space after every period. Another function twoSpaceAfterPeriod (String Parameter) that will return a string with two spaces after every period. It is also a common error to forget to capitalize the first word after a period. Write a function to correct this and return the corrected paragraph.
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
Python Write function stringCount() that takes two string inputs—a file name and a target string— and...
Python Write function stringCount() that takes two string inputs—a file name and a target string— and returns the number of occurrences of the target string in the file. >>> stringCount('example.txt', 'line') 4
C++ Write a recursive function that reverses the given input string. No loops allowed, only use...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. I had asked this before but the solution I was given did not work. #include #include using namespace std; void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sammy";    reverse(name);    cout << name << endl; //should display...
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list strings and the second...
Write a Python function that takes two parameters: the first a list strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT