Skip to main content

Python programe to find the factorial of a number

 Python program to find the factorial of a number

Factorial number of a number is a product from 1 to the number which is from 1 to n where n is the number

Example : factorial of 5 = 1*2*3*4*5 = 120

Code:

#function to find factorial number
def facto(n):
    factorial = 1
    for i in range(1,n+1):
        factorial = factorial * i
    return factorial
#Take the input from the user and store in n
n = int(input())
if n == 0: #factorial of 0 is always 1
    print(1)
else:
    print(facto(n))
#other than 0 we have to find the factorial number by calling the function

Input : 5

Output : 120

There is another method to find factorial number using recursion.

Feel free to check the code in a code editor and try it out and also i am welcome to any suggestion.

Here is the previous post : https://shotwithcode.blogspot.com/2020/12/python-automation-with-selenium.html

Reach through my instagram : https://www.instagram.com/shotwithcode/

Comments

Popular posts from this blog

Best office computer accesories

 Here are some of the best computer accesories for your office at an affordable price in India. 1. Oxyura Gaming Mouse Pad Click here to see the Mouse pad https://amzn.to/3pVY8KL 2. Zebronics Zeb-Alex Wired Usb optical mouse Click here to see and buy the Mouse https://amzn.to/3ILT2t6 3. Usb wired keyboard Click here to see and buy the keyboard https://amzn.to/3mmzjqv 4.Laptop stand Click here to see and buy the laptop stand https://amzn.to/3dTgkih All link are from amazon so go ahead and check it out it is at an afordable price.

How to customize django admin?

 How to customize django admin with our own style? We all know django has it own default admin panel for a project  which look like this But we don't want our admin panel of our project to be name as django administration we want to customize it with our own style like changing the color, background color, text everything we want to change it as per our project UI So here you can do to change the django admin panel Step1: Go to the template folder Step2: Create a folder and name it as an admin so that it is easy for you to understand that this is the admin folder for our templates Step3:Inside an admin folder create a file name as 'base_site.html' in order to make you understand that this file is a file which overwrite the base file.Django has it default base HTML file so in order to customize the admin panel we have to overwrite the base file. Step4: run the server and go to to the admin panel and open developer tool by clicking inspect to see which one we want to  customi

I built a Django weather app using openweatherapp API

 I built a Django weather app using openweatherapp API.  Yes i built this simple weather app using openweatherapp API, it was fun an easy to built with django. How do i built it? I install the module needed for this project, the only module we need is a request module for python since i am using python to built this project. After installing and setting up the project with django i download a template and start with creating the views for the project. Here how goes: 1.First go to openweather app website : https://openweathermap.org/ 2.Signup for an account so that the openweather app will send you an api key 3.After singup with an account go to API and select the API you want to use 4.In an API doc it will attach a link which look like this api.openweathermap.org/data/2.5/weather?q= {city name} &appid= {API key} So we need to replace the {API key} with our own API key. 5.That it for the API so in order to make a request or to call the API in python we use a request module to call