Aug-12-2024, 06:36 AM
At the very early stages of learning Python. Currently learning Python loop functions and what they can do. I'm a bit confused about the continue function available for loops. Here's a short code that I wrote:
import random
count = 0
for attempts in range(1000):
result = random.randint(0, 99)
count = count + 1
if result != 25:
continue
else:
print("You got it. The number is 25")
print("Number of attempts = " + str(count))
break
For every new function that I learn I write a short code showcasing that function. I'm trying to do just that above, having just learnt the continue and break functions. It then dawned on me that the code above is a loop by default. I really don't need to add that continue there. Can anyone help me write a code where the continue is "meaningful" in the sense it isn't redundant? You can give me a simple problem that I can try to code.

Muchas gracias