Coding Global Background
Coding Global

This problem has stumped me, my computer science engineer, and another engineer I know.

0 messages
1 members
Created 4 hours ago
Updated 4 hours ago
Open in Discord
B
Wes
Verified
TO preface I completely understand that there are easier ways to solve the problem i.e(a while loop) that are more effective. However I'm toying with the idea of an indefinite for loop because the idea came to me in a dream. However it's not working and I don't quite understand why.

 time
import random

x = 1
for i in range(x):
    numcheck = random.randint(2, 5)
    if numcheck ==1:
        pass
    elif numcheck !=1:
        x+=1
        print(x)




the original idea was to start X at 1 adding 1 each iteration, in theory keeping the loop running; until the random int hits a 1 and it doesn't add 1, in theory breaking the loop.
it developed a bit into something different but here is a dumbed down verson of the original idea. I don't fully understand how the logic works but it seems python REALLY doesn't like running a for loop indefinitely. Even though I've seen people do it and done similar things in the past. How do I do this 😭 🙏