1

I want to print 10 random number and I try this:

import random
number = 10
while number <= 10:
   print(random.randint(0,9))
   number += 1

but this print next number in the new line. I try below code to fix that but:

import random

number = 10
my_list = []
while number <= 10:
   my_list.append(random.randint(0,9))
   number += 1
print my_list

it display number with , and []

  • Check this answer out: https://stackoverflow.com/questions/493386/how-to-print-without-newline-or-space – folkol Mar 27 '21 at 13:47
  • You meant to initialize `number` variable to zero right? you should edit your question then – Or b Mar 27 '21 at 13:51

2 Answers2

0
import random

randomlist = []

for i in range(0,5):
 n = random.randint(1,30)
 randomlist.append(n)
print(randomlist)

you can read more about it [here][1].

for the basics of printing:https://www.geeksforgeeks.org/print-without-newline-python/

anindiangeek
  • 82
  • 11
0

To print without a new line you should edit the end argument which is set to newline by default, in. You could edit the print command in your first attempt to:

   print(random.randint(0,9), end = " ")
Or b
  • 666
  • 1
  • 5
  • 22