+ 3
How to merge tow codes???
Hallo, how to merge the following tow codes without repeating the "for" method AND with same resault: import random for i in range(5): x = random.randint(1, 6) print(x) for i in range(5): y = random.randint(64, 6464) print(y)
8 Answers
+ 5
Here is a comprehension, that should do the job:
from random import choices
[print(i) for i in choices(range(1,7),k=5)]
print()
[print(i) for i in choices(range(64,6465),k=5)]
# output:
4
6
5
1
2
4545
2674
4494
1708
6232
+ 4
RAJESH SAHU
ohh! that works really well.
+ 3
Not as perfect as you want
import random
x,y=[],[]
for i in range(5):
x.append(random.randint(1,6))
y.append(random.randint(64,6464))
print(*x)
print(*y)
+ 3
First print like so:
5
3
6
4
2
Second print like so:
979
866
1314
3335
6600
And not like this:
1
3434
5
6622
4
1010
6
793
3
+ 3
đđ˘đ˘đđ¨ đđĄđđ˛đđĽ it works thanks for the out of the box thinking.
+ 2
Before we can give you an answer, please tell us what the code should do. Give us a sample for input values and a sample how the output should looks like. Thanks!
0
Concatenating the number-ranges would also be an option:
from random import randint
for r in [(1,6)] * 5 + [(64, 6464)] * 5:
print(randint(*r))
https://code.sololearn.com/cKu5UvQCoeEq/?ref=app