Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Hrithik Sharma6,090 Points
Why the while loop is not working in python?
Function alone works fine but when put it in while it doesn't work do anyone know What's the problem Code:-
import webbrowser import time i = 0 def startBrowser(seconds, url): time.sleep(seconds) webbrowser.open_new(url) while i == 2: startBrowser(10, "www.google.com") i += 1
Steven Parker228,095 Points
The "while" condition is checking to see if "i" is equal to 2. Since "i" starts out set to 0, this condition is not true so the loop never runs.
Perhaps you meant to write: "
while i < 2:" instead?