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

Logistic Regression

  What is Logistic Regression? Logistic regression is Regression as well as Classification machine learning algorithm that comes under Supervised Learning techniques. Logistic regression is used to predict the categorical dependent variable with the help of independent variables. Logistic regression converts its output using the logistic sigmoid function to return a probability value which can then be mapped to two or more discrete classes. Comparison to linear regression Logistic Regression Linear Regression Solves the classification problems Solves the regression problems mostly Predict the categorical dependent variables using set of independent variables Predict the continuous dependent variables using set of independent variables To estimate the accuracy, Maximum likelihood estimation method is used To estimate the accuracy, Least square estimation method is used We get Ca...

Multiclass logistic regression

  Multiclass logistic regression Instead of  y = 0 , 1  we will expand our definition so that  y = 0 , 1... n . Basically we re-run binary classification multiple times, once for each class. Procedure 1.     Divide the problem into n+1 binary classification problems (+1 because the index starts at 0?). 2.      For each class… 3.      Predict the probability the observations are in that single class. 4.      prediction = <math>max(probability of the classes) For each sub-problem, we select one class (YES) and lump all the others into a second class (NO). Then we take the class with the highest predicted value. Softmax activation The softmax function (softargmax or normalized exponential function) is a function that takes as input a vector of K real numbers, and normalizes it into a probability distribution consisting of K probabilities proportional to the exponentials of...

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...