I'm having almost the exact same issue as here, except the solution listed there did not work for me.
I'm running this on my local machine, and my memory and CPU usage seems fine in task manager. (6 cores, 12 gigs of ram)
I saw this problem first in with an online IDE called repl.it. I have a simple code that generates a Math problem in the form of an SQL entry.
Here is a screenshot of my output.
The loop was only ran 5 times as opposed to the requested 300, then froze. I ran it again and the loop ran 7 times.
I repeated it, and each time, the number of times the loop ran varied drastically.
- After making sure my code was error free, I thought perhaps there was something wrong with the online IDE, so I ran it on my local command console, however, the same thing ended up happening. The code would not run completely.
- At this point, I decided there was something wrong with the print function, perhaps. I tried writing to a .txt file instead, and the code didn't run at all.
- I realized there must be something wrong with my computer then, and
ran the code on my old laptop. The same, exact thing happened.
Here is my full code:
import random
entries = input("Enter the number of entries you would like to insert");
sqltext = open("sql.txt", "w")
sqltext.write("INSERT INTO `toredatabase`.`questions` (`id`, `category`, `question`, `Correct_Answer`, `answer_A`, `answer_B`, `answer_C`, `answer_D`, `Details`) VALUES")
print("INSERT INTO `toredatabase`.`questions` (`id`, `category`, `question`, `Correct_Answer`, `answer_A`, `answer_B`, `answer_C`, `answer_D`, `Details`) VALUES")
for x in range(int(entries)):
r1 = random.randint(0, 1000)
r2 = random.randint(0, 1000)
correctanswer = r1+r2
possibleanswers = []
ans1 = r1+r2+random.randint(-100,100)
ans2 = r1+r2+random.randint(-100,100)
ans3 = r1+r2+random.randint(-100,100)
ans4 = r1+r2+random.randint(-100,100)
possibleanswers.append(correctanswer);
possibleanswers.append(ans1);
possibleanswers.append(ans2);
possibleanswers.append(ans3);
a = random.choice(possibleanswers)
b = random.choice(possibleanswers)
while b == a:
b = random.choice(possibleanswers)
c = random.choice(possibleanswers)
while c == a or c == b:
c = random.choice(possibleanswers)
d = random.choice(possibleanswers)
while d == c or d == b or d == a:
d = random.choice(possibleanswers)
print(f"('', 'Math', 'What is {r1} + {r2}?', '{correctanswer}','{a}', '{b}', '{c}', '{d}', 'Addition'),")
sqltext.write(f"('', 'Math', 'What is {r1} + {r2}?', '{correctanswer}','{a}', '{b}', '{c}', '{d}', 'Addition'),")
You can run it yourself and see if you are met with similar results.
What in the world is the problem here?