簡體   English   中英

無法在同一行打印 output

[英]Cannot print output on the same line

我希望我的 output 打印在一行上,並且在用戶輸入后應該有間隙。

 i = 1
  x = int(input("enter a number to loop" ))

  while(i<=x):
       print('\n',i, end= " ")
       i += 1

對於我的代碼,我的 output 不在同一行。 如何在一行上打印 output。

您在打印 function.. 中添加了一個 \n

i = 1
x = int(input("enter a number to loop\n"))

while(i <= x):
    print(i, end=" ")
    i += 1

這應該可以解決您的問題

i = 1
x = int(input("enter a number to loop " ))
print("\n")
while(i<=x):
   print(i, end= " ")
   i += 1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM