+ 1

How to print random numbers of any range be printed on same line not individually at new line using Python 3

25th Feb 2017, 6:23 AM
Smaranjit Saha
Smaranjit Saha - avatar
5 Answers
+ 11
import random print("here is a random number between 1 and 400:",random.randint(1,400))
25th Feb 2017, 7:14 AM
Ahri Fox
Ahri Fox - avatar
+ 7
from random import randint myrandoms = [randint(0,x) for x in range (20)] print (myrandoms)
25th Feb 2017, 7:23 AM
Oma Falk
Oma Falk - avatar
+ 3
@smaranjit show me that please
25th Feb 2017, 9:33 AM
Oma Falk
Oma Falk - avatar
+ 1
@Oma Falk I wanted this type output, thanks.... I have tried to generate roll no of range(8) using def and magic method... successful though complicated one
25th Feb 2017, 9:28 AM
Smaranjit Saha
Smaranjit Saha - avatar
0
import random class Random: def __init__(self,ran): self.ran=ran def __getitem__(self,index): return self.ran[index+random.randint(-1,1)] rand_om=Random(["0", "1"," 2", "3"," 4", "5"," 6", "7"," 8"]) a=rand_om[0]+rand_om[1]+rand_om[2]+rand_om[3]+rand_om[4]+rand_om[5]+rand_om[6]+rand_om[7]+rand_om[8] print("guess what your 9digit may be"+a)
25th Feb 2017, 1:09 PM
Smaranjit Saha
Smaranjit Saha - avatar