0

so I want an output like this 5, 7, 23, 15, 6, 3 all random in one line Matrix

I know I could do

from random import randrange
for i in range(5):
    print(f' {randrange(50)}')

the problem with this they will not be in one line.

so I tried this print(f' {randrange(100)}' * 5) but the output show similar numbers like this 27, 27, 27, 27, 27

any solution?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
  • Does this answer your question? [Print in one line dynamically](https://stackoverflow.com/questions/3249524/print-in-one-line-dynamically) – fynmnx Mar 03 '21 at 17:28
  • Voting to reopen since OP wants to join on **comma-space** (`', '`), not just space, without a trailing comma. – wjandrea Mar 03 '21 at 17:39
  • If my answer helped you, please consider accepting it. This tells others that the issue is resolved and allows them to find the correct answer more easily. – M-Chen-3 Mar 19 '21 at 20:32

1 Answers1

0

Just add an end=" " to the print statement. This will put a space between each number instead of a new line.

from random import randrange
for i in range(5):
    print(f"{randrange(50)}", end=" ")
M-Chen-3
  • 2,036
  • 5
  • 13
  • 34