How to define WHILE Loop in Python?
DATA MUNGING DATA CLEANING PYTHON MACHINE LEARNING RECIPES PANDAS CHEATSHEET     ALL TAGS

How to define WHILE Loop in Python?

How to define WHILE Loop in Python?

This recipe helps you define WHILE Loop in Python

0

Recipe Objective

In python, sometimes we want that same function to be iterated on many values. So for this passing every value from the function may be a hectic task. We can do this by defining a loop

So this is the recipe on how we can define WHILE Loop in Python.

Step 1 - Defining Loop

sales = 7 while sales > 0: print("sales is greater than zero") sales = sales - 1

Here we have defined While loop which iterate the functions passed inside it till the condition inside the while loop is true. Here we have given the condition that till sales is greater than zero it will iterate and inside the loop we have passed the function to decrease the sales by 1 in each step. So the output comes as

sales is greater than zero
sales is greater than zero
sales is greater than zero
sales is greater than zero
sales is greater than zero
sales is greater than zero
sales is greater than zero

Relevant Projects

Data Science Project - Instacart Market Basket Analysis
Data Science Project - Build a recommendation engine which will predict the products to be purchased by an Instacart consumer again.

Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Solving Multiple Classification use cases Using H2O
In this project, we are going to talk about H2O and functionality in terms of building Machine Learning models.

Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

Deep Learning with Keras in R to Predict Customer Churn
In this deep learning project, we will predict customer churn using Artificial Neural Networks and learn how to model an ANN in R with the keras deep learning package.

Forecast Inventory demand using historical sales data in R
In this machine learning project, you will develop a machine learning model to accurately forecast inventory demand based on historical sales data.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Perform Time series modelling using Facebook Prophet
In this project, we are going to talk about Time Series Forecasting to predict the electricity requirement for a particular house using Prophet.