0
Is this working? How can i tell?
Sometimes it works perfectly, sometimes it says Time Limit Exceeded, in which case, how do i know if its working or what the problem is? What is the time limit? https://code.sololearn.com/ce2gnZcMy883/?ref=app
7 Réponses
+ 3
Your code has an infinite loop.
playerhp is > 0, wildgoblinatk is a random number which might be 0, if you subtract 0 from a positive number it won't change, while userhp > 0 will always be true => infinite loop.
Also, the condition while (userhp > 0) or (enemyhp <= 0) is wrong. It will only be executed if the player is alive or the enemy is dead (?).
+ 3
Put
playeratk = random.randint(0, 3)
wildgoblinatk = random.randint (0, 2)
in the while loop
+ 2
When it says "Time Limit Exeeded", it just took to long to execute your code. This is related to your internet speed and the Sololearn servers.
There isn't a Problem with your code.
+ 1
@Anna okay, fixed it, thanks for pointing that out!
0
Thanks man! So would it be better to run long codes on something other than Sololearn since it apparently cant handle it?
0
Yes, definitely.
0
Anna the purpose of the while loop should be that it keeps substracting wildgoblinatk from the playerhp and vice versa until either ones dead. In that case, even if the random number is 0 and ohhhh wait, the random number doesnt change for each go does it, its fixed? If not, what would be a good solution as to how to randomize the damage each go so even if its 0 one time, it can be another number next time so it wont be a inifinite loop?
Also yes, silly mistake, thanks for pointing that out!