Python Programming

Functions and Modules

  1. Write a program that finds the greatest of three given numbers using functions. Pass the numbers as arguments.
  2. Write a program that prints the time taken to execute a program in Python.
  3. Write a function that returns the absolute value of a number.
  4. Write a program that uses a lambda function to multiply two numbers.
  5. Write a program that passes a lambda function as an argument to another function to compute the cube of a number.
  6. Write a function is_prime() that returns a 1 if the argument passed to it is a prime number and a 0 otherwise.
  7. Write a function that accepts an integer between 1 and 12 to represent the month number and displays the corresponding month of the year (For example, if month 1, then display JANUARY).
  8. Write a function is_leap_year which takes the year as its argument and checks whether the year is a leap year or not and then displays an appropriate message on the screen.
  9. Create a program that combines two strings using recursion.
  10. Develop a program that takes an integer input and prints its reverse using recursion.
  11. Write a program that swaps the values of two variables declared as global variables.
  12. Implement a program to calculate F(x, y), defined as F(x, y) = F(x - y, y) + 1 if y is less than or equal to x.
  13. Write a program to compute F(n, r) using the recursive definition F(n, r) = F(n - 1, r) + F(n - 1, r - 1).
  14. Design a program to calculate lambda(n) for all positive integers n, where lambda(n) is recursively defined as lambda(n) = lambda(n/2) + 1 if n is greater than 1.
  15. Create a program to compute F(M, N), defined recursively as F(M, N) = 1 if M = 0 or if 1 ≤ N ≤ M, and F(M, N) = F(M - 1, N) + F(M - 1, N - 1) otherwise.
  16. Implement a program that performs basic calculator operations, including addition, subtraction, multiplication, and division of two integers.
  17. Create a function that calculates the hypotenuse of a right-angled triangle.
  18. Write a function that takes an integer n as input and returns the average of all numbers from 1 to n.
  19. Develop a program that determines the largest of three integers using functions.
  20. Write a program that calculates the area of a triangle using a defined function.
  21. Create a program using a function to compute x raised to the power of y, where y can be either negative or positive.
  22. Implement a program that calculates the compound interest for given principal, rate of interest, and number of years using the function C(n,r).
  23. Write a program using a function to return both the surface area and volume of a sphere.
  24. Develop a program that reverses a string using recursion.
  25. Write a program that reverses a string without employing recursion.
  26. Implement a program to calculate exp(x,y) using recursion.
  27. Create a program to calculate exp(x,y) without using recursion.
  28. Write a program that prints the Fibonacci series utilizing recursion.
  29. Develop a program that prints the Fibonacci series without recursion.
  30. Define a function that converts a temperature value from Celsius to Fahrenheit.
  31. Write a function that prints a table of binomial coefficients based on the formula:
    B(m, x) = (m!) / (x!(m - x)!) where m > x.
    (Hint: B(m, 0) = 1, B(0, 0) = 1, and B(m, x) = B(m, x-1) * [(m - x + 1) / x])
  32. Implement a function named printStatus that takes a status code 'S', 'M', 'D', or 'U' and returns the corresponding string 'Separated', 'Married', 'Divorced', or 'Unmarried'. If an invalid code is provided, display an appropriate message. Make sure to include a docstring for your function.
  33. Write a function that accepts three integer values and returns True if any of the integers is 0; otherwise, it returns False.
  34. Create a function that accepts three integers and returns True if they are in sorted order; otherwise, it returns False.
  35. Define a function that accepts two positive integers n and m, where m <= n, and returns the numbers between 1 and n that are divisible by m.

Find it difficult?

Don’t lose heart, don’t be under confident, just be consistent in your preparation and be sure of everything you’ve studied. You can request a class so that we can help you understant this topic.

Feel Confident?

Your first step in learning any new topic is to be aware of your strengths and weaknesses. Once you know this, your self-preparation can be meaningful and result-oriented. Attempt an quiz to get tested.