How can I use random in python3? Because each time I import random library I get runtime error.
Suppose you want a random number in range [0,10)
import random
number = random.randrange(10)
in this task this program
while (True):
val = int(input())
if (val == 42):
break
print(val)
gets AC
but this:
import random
while (True):
val = int(input())
if (val == 42):
break
print(val)
get runtime error. So I can’t import random library to used random.randrange()
in this task this program
while (True):
val = int(input())
if (val == 42):
break
print(val)
gets AC
but this:
import random
while (True):
val = int(input())
if (val == 42):
break
print(val)
get runtime error. So I can’t import random library to used random.randrange()
I don’t know what exactly are you trying to say. Check my submissions, both AC: http://ww2.codechef.com/viewsolution/2123384
and http://ww2.codechef.com/viewsolution/2123387
Your submission http://ww2.codechef.com/viewsolution/2123343 has a fault: you have used random.randrange() without importing random => might be a reason for RTE
You have to read carefully @novgosh is writing about Python3, while you are not!!! Also he asked about 2123013 and not 2123343 which was probably a test only…
@betlista >> Oh, then its an old issue on Codechef. http://discuss.ww2.codechef.com/questions/3835/python-code-throwing-runtime-error-on-including-an-import-statement
Linking a similar question on SO http://stackoverflow.com/questions/11929701/why-is-seeding-the-random-generator-not-stable-between-versions-of-python