我不打算制作一个程序,根据另一个输入打印输入一定次数。
msg = input ("What is your message?")
times = input ("How many times do you wan't your message repeated?")
for times in range(6):
print(msg)
答案 0 :(得分:1)
如果要输入字符串,则必须使用raw_input()。您的范围运算符中也存在错误。像这样使用它:
msg = raw_input('What is your message?')
times = raw_input("How many times do you wan't your message repeated?")
for i in range(int(times)):
print(msg)
输出:
What is your message? Hello World.
How many times do you wan't your message repeated?3
Hello World.
Hello World.
Hello World.
Process finished with exit code 0
答案 1 :(得分:0)
您需要迭代0到times
之间的一系列数字,但是您还需要将times
转换为整数。
为此,for
循环必须为for i in range(int(times)):