如何让这个函数在同一行中重复用户给定的相同字符?相反,它在每行上分别打印
character_to_enter = input('What character would you like to repeat?: ')
character_count = input("How many " + character_to_enter + "'s would you like to enter?: ")
def repeater(character_count):
for repeats in range(int(character_count)):
print(character_to_enter)
repeater(character_count)
输出与上面的当前代码类似
What character would you like to repeat?: f
How many f's would you like to enter?: 2
f
f
Process finished with exit code 0
我需要它看起来像这样
What character would you like to repeat?: f
How many f's would you like to enter?: 4
ffff
Process finished with exit code 0
实现这一点的最简单方法之一是使用print的“end”参数。像这样:
这种方式不是用默认换行符结束每次打印,而是不添加任何字符
相关问题 更多 >
编程相关推荐