Function Practice Questions

  1. Write a function that takes two numbers as input and returns their sum.

def add_numbers(num1, num2):
    return num1 + num2
  1. Write a function that takes a list of numbers as input and returns the maximum value in the list.

def find_max(numbers):
    return max(numbers)
  1. Write a function that takes a string as input and returns the number of vowels in the string.

def count_vowels(word):
    vowels = "aeiou"
    count = 0
    for char in word:
        if char.lower() in vowels:
            count += 1
    return count
  1. Write a function that takes a list of words as input and returns a new list that contains only the words that start with a vowel.

def start_with_vowel(words):
    vowels = "aeiou"
    result = []
    for word in words:
        if word[0].lower() in vowels:
            result.append(word)
    return result
  1. Write a function that takes a list of numbers as input and returns a new list that contains only the even numbers.

  1. Write a function that takes a string as input and returns the string in reverse order.

  1. Write a function that takes a list of numbers as input and returns the average value of the numbers.

  1. Write a function that takes a string as input and returns a new string that has all the vowels removed.

  1. Write a function that takes a list of words as input and returns a new list that contains only the words that have more than five characters.

  1. Write a function that takes a list of strings as input and returns a new list that contains the length of each string.

  1. Write a function that takes a list of numbers as input and returns the sum of the squares of all the numbers in the list.

  1. Write a function that takes a string as input and returns the number of words in the string.

  1. Write a Python function to find the maximum of three numbers.

  1. Write a Python function to reverse a string.

  1. Write a Python function to check if a string is a palindrome.

  1. Write a Python function to calculate the factorial of a number.

  1. Write a Python function to check if a number is prime.

  1. Write a Python function to find the greatest common divisor (GCD) of two numbers.

  1. Write a Python function to convert a string to title case.

  1. Write a Python function to calculate the area of a circle.

  1. Write a Python function to generate a list of all prime numbers up to a given number.

  1. Write a Python function to calculate the Fibonacci sequence up to a given number of terms.

Last updated