Skip to main content
 首页 » 编程设计

python之无换行 python

2025年05月04日27yjmyzz

<分区>

我正在尝试使用 random 打印随机数,但是当我尝试使用 end= "" 在一行中打印输出时,输出不会显示任何内容,直到我中断程序。

import random 
import time 
while True: 
    x = random.randint(1,6) 
    print(x, end=" ") 
    time.sleep(1) 

打断后的输出是这样的:

C1 2 3 5 5 4 5 4 1 --------------------------------------------------------------------------- 
KeyboardInterrupt                         Traceback (most recent call last)