I have a problem with my simple python program. While the loop is getting stuck after 6 cycles every time unless it meets desired conditions before that.
I am new to software development and python. I tried to use pdb to find what's going on, but couldn't figure out how to use it .. yet. Also any suggestions on how to make this code better cleaner etc are welcome.
Here is the code:
import random as rd
random = rd.randint(1,48)
odd = 0
even = 0
low_n = 0
high_n = 0
rdlist = []
condition = False
count = 0
def loop(rdlist):
global random,odd,even,low_n,high_n
for _ in range(6):
while random not in rdlist:
rdlist.append(random)
if random % 2 == 1:
odd += 1
if random % 2 == 0:
even += 1
if random <= 24:
low_n += 1
if random >= 25:
high_n += 1
while random in rdlist:
random = rd.randint(1,48)
def validation():
global condition
if odd == even == high_n == low_n == 3:
condition = True
rdlist.sort()
print(rdlist)
else:
condition = False
loop(rdlist)
loop(rdlist)
while condition != True:
validation()
question from:
https://stackoverflow.com/questions/65648305/while-loop-stops-after-few-cycles 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…