Example python programs: Functions basics

Simple python programs to practice:

1) Write a Python function Factorial(n) which returns the factorial of the given number(n).

2) Write a Python function, Square(num) which returns the square of the given number(num).

3) Write a Python function, Sum(n) which returns the sum of first n numbers.

4) Write a Python function, Palindrome(num) that accepts an integer num as input and returns true/false based on condition.

    Ex: num = 12321 ---> output = 12321 ----> then given number is palindrome.

5) Write a Python function, check_strong_number(num) that accepts a positive as input, and returns true/false based on condition.
  • A number is said to be a Strong number if the sum of the factorial of each digit is equal to the given number.
   Ex: 145 is strong number as (1! =1) + (4! = 24) + (5! = 120) = 145.

No comments:

Post a Comment

You might also like

Deploy your Django web app to Azure Web App using App Service - F1 free plan

In this post, we will look at how we can deploy our Django app using the Microsoft Azure app service - a free plan. You need an Azure accoun...