Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我想要这样的输出5, 7, 23, 15, 6, 3 在一行矩阵中都是随机的
5, 7, 23, 15, 6, 3
我知道我能做到
from random import randrange for i in range(5): print(f' {randrange(50)}')
与此相关的问题他们不会排成一行。
所以我尝试了这个 print(f' {randrange(100)}' * 5),但输出显示类似的数字27, 27, 27, 27, 27
print(f' {randrange(100)}' * 5)
27, 27, 27, 27, 27
任何解决方案?
end=" "只需在print语句中添加一个。这将在每个数字之间放置一个空格,而不是换行。
end=" "
print
from random import randrange for i in range(5): print(f"{randrange(50)}", end=" ")