breaking a while loop
Hello I did not post in a while (not pun intended). I am doing a course on Udemy now. One of the section had a list of problem to solve. One is to do a python code that give you a succession of prime number until you tell it to stop. Calculating prime number and putting them on a list is not complicated, but I am not able to make code stop. Lp = [] def prime(n): l = range(2,n) f = 0 while f == 0: for x in l: if n%x == 0: n += 1 prime(n) else: Lp.append(n) print(f" {n} is prime") if input('type y for one more prime ') == 'y': n += 1 prime(n) else: print(f"The prime found in this session are {Lp}") f = 1 prime(5) I tried different technic ( especially the "break" function) . But nothing that's work. The code print me the list as soon as you put another imput than 'y' but kept asking if you want a new prime.. What I am missing here ? ps : I know that break work only with if statement, but various variation did not worked either.