5.24. Functions and Strings Write Code Questions

  1. Write a function called start_a that takes in string as a parameter and returns True if the string starts with a lowercase a and False otherwise. For example, start_a('apple') should return True.

    Write a function called start_a that takes in string as a parameter and returns True if the string starts with a lowercase a and False otherwise. For example, start_a('apple') should return True.

  2. Write a function called square_length that takes in area as a parameter and returns "A square with an area of (area) square feet has a side length of (side length) feet.". The side length is the square root of the area. Use math.sqrt(area) to get the square root of area. For example, square_length(36) should return "A square with an area of 36 square feet has a side length of 6.0 feet.".

  3. Write a function called use_semicolon that takes in sentence1 and sentence2 as parameters and returns both sentences joined by a semicolon with the correct grammar. This means that sentence1 shouldn’t have a terminal punctuation mark, there should be a space after the semicolon, and sentence2 should start with a lowercase letter. For example, use_semicolon('The sun is bright.', "Let's go outside.") should return "The sun is bright; let's go outside.". (Note: Assume both sentence1 and sentence2 are simple and complete sentences with proper grammar.)

    Write a function called use_semicolon that takes in sentence1 and sentence2 as parameters and returns both sentences joined by a semicolon with the correct grammar. This means that sentence1 shouldn’t have a terminal punctuation mark, there should be a space after the semicolon, and sentence2 should start with a lowercase letter. For example, use_semicolon('The sun is bright.', "Let's go outside.") should return "The sun is bright; let's go outside.". (Note: Assume both sentence1 and sentence2 are simple and complete sentences with proper grammar.)

  4. Write a function called change that takes in string as a parameter and returns a new string with the first two characters uppercased, the last two characters lowercased, and the remaining characters in the middle moved to the front of the string with the first letter capitalized. For example, change('hello') should return "LHElo", and change('pumpkin') should return "MpkPUin". (Note: Don’t worry about accounting for strings that are 4 characters or less.)

  5. Write a function called first_a_gone that takes in string as a parameter and returns a new string without the first lowercase ‘a’. For example, first_a_gone('australia') should return "ustralia". (Note: Don’t worry about accounting for strings that don’t have a lowercase ‘a’.)

    Write a function called first_a_gone that takes in string as a parameter and returns a new string without the first lowercase ‘a’. For example, first_a_gone('australia') should return "ustralia". (Note: Don’t worry about accounting for strings that don’t have a lowercase ‘a’.)

You have attempted of activities on this page