首页 > 解决方案 > 我如何循环/重复/范围(无论你怎么称呼它)在python中打印文本?

问题描述

我在这段代码中做错了什么,它不会循环打印?请发送正确答案。

repr(
"input()means you tell the computer something"
)
range(
"input()means you tell the computer something"
)

标签: pythongoogle-colaboratory

解决方案


我不太确定你想用这段代码实现什么,但是有多种方法可以在 python 中重复打印一个字符串。这里有几种方法:

  1. 使用 while 循环(这将无限运行)
while True:
    print("input()means you tell the computer something")
  1. 使用 for 循环(如果您想打印一定次数)
times = int(input("How many times do I repeat?: "))
for i in range(times):
    print("input()means you tell the computer something")

我希望这能回答你的问题


推荐阅读