How to define WHILE Loop in Python?

How to define WHILE Loop in Python?

This recipe helps you define WHILE Loop in Python
In [1]:
## How to define WHILE Loop in Python
def Kickstarter_Example_59():
    print()
    print(format('How to define WHILE Loop in Python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # Load Libraries
    import random

    # Create a variable of the true number of Sales of a Retail event
    sales = 7

    # Create a variable that is denotes if the while loop should keep running
    running = True

    # while running is True
    while running:
        # Create a variable that randomly create a integer between 0 and 10.
        guess = random.randint(0,10)

        # if guess equals number of sales,
        if guess == sales:
            print('Correct!')
            running = False

        # else if guess is lower than slaes
        elif guess < sales:
            print('No, it is higher.')
        else:
            print('No, it is lower')

Kickstarter_Example_59()
************************How to define WHILE Loop in Python************************
No, it is lower
No, it is lower
No, it is lower
Correct!


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from Altimetrik
1 developer from LTI
1 developer from ANAC
1 developer from MudraCircle
1 developer from HvH
1 developer from Vodafone
1 developer from KPMG
1 developer from YASH Technologies