+ 1

Why am I getting 'time limit exceeded' messages?

I'm very new to coding (less than a month) and I wrote a simple code to select random letters and numbers for the game BINGO. The code is supposed to wait 2 seconds before starting, then print random combinations of letters B-I-N-G-O and numbers 1-10. Then the code is supposed to wait 5 seconds and then print another output. This is supposed to happen 100 times. import random, time bingo = "BINGO" lett = random.choice(bingo) num = random.randint(1,10) num = str(num) time.sleep(2) for i in range(100): print(lett + num) time.sleep(5) I'm not getting any syntax errors, but I keep getting a time limit exceeded message in output. Is something inherently wrong with my code or is code playground just not able to run it properly? Also, if there's a way to have only unique combinations printed I'd love some advice. Thanks!

4th Dec 2018, 8:01 PM
Yup
7 Réponses
+ 3
Kishalaya Saha He probably meant that if a combination has been printed once, it is not printed again. For instance, if the combination 'B1' is printed, any other combination cannot be B1.
5th Dec 2018, 6:30 PM
Mayur Garg
Mayur Garg - avatar
+ 3
The time limit is about 5 seconds on Sololearn. And sleep doesn't really work well here. All the outputs are displayed together, so it's sort of pointless. P.S. Could you please explain what you meant by unique combinations with examples?
4th Dec 2018, 8:03 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 3
Gregory Fawver https://code.sololearn.com/chwQHYGfj1DS/?ref=app Check this out... Notice the changes I made - 1. Removed the sleep function calls cause as Kishalaya Saha mentioned, they are pointless here at SoloLearn. If you want to use that functionality, try using python on a desktop or a laptop. 2. Added a set which stores all the values to be printed so we can check that we are not printing any value twice. 3. I lowered the count to 10 combinations cause 100 combinations aren't possible as per your requirements. Max what you can get is 50.
5th Dec 2018, 6:46 PM
Mayur Garg
Mayur Garg - avatar
+ 2
Thanks Mayur for the clarification, and for the great answer. Gregory, if you feel like being a little fancy, you could try this: from random import sample options = [l+str(n) for l in "BINGO" for n in range(1, 11)] print(*sample(options, k=20), sep="\n") random.sample() doesn't allow for repeats at all. But if you just want the code not to keep printing the same one over and over (but some repeats are allowed), you could still use choice() and randint. Just make sure to do that inside the for loop, not before.
5th Dec 2018, 7:19 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
Mayur Garg Thank you!
5th Dec 2018, 6:48 PM
Yup
+ 1
Kishalaya Saha right on thanks for the help.
5th Dec 2018, 7:29 PM
Yup
0
That's exactly what I meant
5th Dec 2018, 6:33 PM
Yup