python - 在向用户询问循环中的新变量之前在打印后添加一个空行
问题描述
我正在做一些简单的 python 练习,目标是询问用户一个单词,并且该单词在循环中被打印了多次。问题是程序在打印用户给定的变量后不打印空行。
我已经尝试了各种 \n 配置,但都没有成功。
我的程序是:
def printer(a,b):
i=0
for i in range(0,b):
print(a)
while True:
text=input("Give text: ")
if text=="stop":
print("Stopping.") ##This works fine
break
else:
number=int(input("Give number: "))
printer(text, number)
现在想要的打印是:
Give text: text
Give number: 2
text
text
Give text: text
Give number:
但它打印它时没有任何空行:
Give text: text
Give number: 2
text
text
Give text: text
Give number:
正如我之前提到的,我尝试了各种 \n- 和 ""- 配置,但都没有成功。在向用户询问新变量之前,如何让程序在打印末尾添加一个空行。
解决方案
您所需要的只是for
循环后的打印:
def printer(a,b):
i=0
for i in range(0,b):
print(a)
print()
while True:
text=input("Give text: ")
if text=="stop":
print("Stopping.") ##This works fine
break
else:
number=int(input("Give number: "))
printer(text, number)
推荐阅读
- nginx - 使用 nginx 将 www 重定向到非 www godaddy
- ios - 让 WKWebView 覆盖整个屏幕
- django - Django - collectstatic 后出现 500 内部服务器错误
- android - Spotify 如何与 Android 上的默认时钟应用程序集成
- google-chrome - GQUIC 如何影响 WebRTC 流程?
- ios - 如何检查 SVG 文件验证?
- python - Python - 扭曲的反应器 - 从线程的角度来看 callLater 和 callFromThread 之间的区别
- java - 将逗号分隔的字符串转换为带有尾随逗号分隔的数组列表
- java - 从第二个表中获取计数(生成的发票数量)和从第三个表中获取总和(订单总数) - MySQL
- vba - 加快按名称查找文件夹