Basic While Loop does not work

333
May 04, 2017, at 10:07 PM

Here's my code:

from time import sleep
def func():
    print("Hello world")
if __name__ == '__main__':
    i = 0
    rep = 5
    while i < rep:
        func()
        print("Out")
        sleep(5)

When I run it, this is the only output I get:

Hello World
Out

Seems that it cannot continue with the loop.

Does anyone know why this code does not work? Thanks for help!

UPDATE: Yes, i volontary not updated i, trying an alternative to while True loop. I waited more than 5s

UPDATE n. 2: I did this and the output remains the same. Obviously "Out" is printed after 5 seconds. But the loop does not restart.

from time import sleep
def func():
    print("Hello world")
if __name__ == '__main__':
    while True:
        func()
        sleep(5)
        print("Out")
Rent Charter Buses Company
READ ALSO
Using Pyvaru for bulk data (CSV) validation

Using Pyvaru for bulk data (CSV) validation

Am looking for a generic validator module to assist in sanitizing data and importantly, giving back an error log stating why data has been rejectedAm working primarily with CSV files each with an average of 40 columns and with about 40,000 rows

368
how to create an object which takes as a parameter another object using python

how to create an object which takes as a parameter another object using python

I want to create my own logging class: which writes some data to a text file

370
Measure distance with ultrasonic sensor and Raspberry

Measure distance with ultrasonic sensor and Raspberry

I am trying to measure a distance with ultrasonic sensor and everything looks well but when I leave the program for a some minutes (3-4 minutes) working, the program stops the measure of distance

275
Django-MSSQL error when creating a user from the admin panel

Django-MSSQL error when creating a user from the admin panel

I am a bit stuck, my app is nearly finished and I have a problem, I can't create a user with the admin panel

459