5.36. Functions and Loops Write Code Questions

  1. Write a function called list_starts_with_a that takes in lst as a parameter and returns a new list with the words from lst that start with “a”. For example, list_starts_with_a(["alphabet", "apple", "banana", "coding", "amazing"]) would return ["alphabet", "apple", "amazing"].

    Write a function called list_starts_with_a that takes in lst as a parameter and returns a new list with the words from lst that start with “a”. For example, list_starts_with_a(["alphabet", "apple", "banana", "coding", "amazing"]) would return ["alphabet", "apple", "amazing"].

  2. Write a function called sentence_without_vowels that takes in string as a parameter and returns a new string that consists of only characters that are not vowels. For example, sentence_without_vowels('apple') would return "ppl".

  3. Write a function called draw_square that takes in num as a parameter and returns a string that consists of a square made of “*” with the dimensions num times num. Note: ignore values that are less than or equal to zero. For example, draw_square(4) would return "****\n****\n****\n****".

    Write a function called draw_square that takes in num as a parameter and returns a string that consists of a square made of “*” with the dimensions num times num. Note: ignore values that are less than or equal to zero. For example, draw_square(4) would return "****\n****\n****\n****".

  4. Write a function called check_prime_num that takes in num as a parameter and returns True if num is a prime number and False otherwise. For the purposes of this question, there is no need to test for values of num that are less than two. For example, check_prime_num(5) should return True.

  5. Write a function called factorial that takes in num as a parameter and returns the factorial value. Ignore checking numbers that are less than 1. For example, factorial(5) would return 120.

    Write a function called factorial that takes in num as a parameter and returns the factorial value. Ignore checking numbers that are less than 1. For example, factorial(5) would return 120.

You have attempted of activities on this page