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

19th Apr 2019, 6:18 AM
Zinnur Hossain
Zinnur Hossain - avatar
7 Answers
+ 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 (?).
19th Apr 2019, 8:16 AM
Anna
Anna - avatar
+ 3
Put playeratk = random.randint(0, 3) wildgoblinatk = random.randint (0, 2) in the while loop
19th Apr 2019, 3:14 PM
Anna
Anna - avatar
+ 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.
19th Apr 2019, 7:18 AM
Bela Brockmann
Bela Brockmann - avatar
+ 1
@Anna okay, fixed it, thanks for pointing that out!
19th Apr 2019, 4:09 PM
Zinnur Hossain
Zinnur Hossain - avatar
0
Thanks man! So would it be better to run long codes on something other than Sololearn since it apparently cant handle it?
19th Apr 2019, 7:19 AM
Zinnur Hossain
Zinnur Hossain - avatar
0
Yes, definitely.
19th Apr 2019, 8:05 AM
Bela Brockmann
Bela Brockmann - avatar
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!
19th Apr 2019, 3:10 PM
Zinnur Hossain
Zinnur Hossain - avatar