Skip to main content

TOP 10 Mostly asked Basic Programs in python

 

1. Python Program for factorial of a number

Factorial of a number is products of all natural number to till that number.
for eg:
5!=5*4*3*2*1=120
100!=1*2*3*...........................................99*100

Logic: Suppose we have to find the the factorial of a number n then we required to multiply all number starting from 1 to n
n!=1*2*3*4*.........................(n-1)*n!
So we need to multiply all these numbers in this range 1 to n+1
why did I not  take range 1 to n because range function gives values less than 1 
OUTPUT:

Implementation using Loop

                                                         Implementation using  Recursion


Comments

Popular posts from this blog

Linear Regression

What is Linear Regression? Linear Regression is a supervised machine learning algorithm where the predicted output is continuous and has a constant slope. It’s used to predict values within a continuous range, (e.g. sales, price) rather than trying to classify them into categories (e.g. cat, dog). There are two main types: Simple regression Simple linear regression uses traditional slope-intercept form, where  m  and  c  are the variables our algorithm will try to “learn” to produce the most accurate predictions.  x  represents our input data and  y represents our prediction.                                                       y = mx + c Multivariable regression A more complex, multi-v...

Introduction to Machine Learning

What is Machine learning? The meaning of Machin Learning is machine learns itself with its experience.  Machine learning (ML) is a type of artificial intelligence (AI) that allows software applications to become more accurate at predicting outcomes without being explicitly programmed to do so. ML improve the performance of a computer program using sample data or past experience.  We have to create a model and then we have to train the model which will provide the prediction on the basis of machine learning algorithms. For eg: A robot learns with its past experience and improve itself.   Classification of Machine Learnings algorithms: Supervised Learning: Supervised learning, as the name indicates, has the presence of a supervisor as a teacher.  It is defined by its use of labelled datasets to train algorithms that to classify data or predict outcomes accurately. For eg:   Supposed to identify the fruits in the basket we mu...