-2

I wan't to make a program which will print an input a certain number of times based on another input.

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)
Josh
  • 1

2 Answers2

1

You have to use raw_input() if you want to enter strings. There is also an error in your range-operator. Use it like this:

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)

Output:

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
Jack O'Neill
  • 1,032
  • 2
  • 19
  • 34
  • 1
    It would be better security-wise to use `raw_input` and convert to `int`, as `input` will execute whatever you enter. Also, you can simply use `range(times)` (after converting `range` to `int`). – Farhan.K Nov 22 '16 at 16:16
  • I meant to say after converting `times` to `int`. (Can't edit my comment above) – Farhan.K Nov 22 '16 at 16:25
0

You need to iterate on a range of numbers between 0 and times, however you also need to convert times to an integer.

In order to do that your for loop needs to be for i in range(int(times)):

MrPromethee
  • 721
  • 9
  • 18