2
\$\begingroup\$
x = int(input("Choose the number of times you want to spam. "))

y = input("What message do you want to spam? ")

w = x + 1

for i in range(1,w):
    print(y)

Any way to make this program better? I'm currently learning Python.

\$\endgroup\$
8
\$\begingroup\$
  1. Use descriptive variable names
  2. No need to add one to x and then use range(1, w) - get used to using zero-based numbering
  3. By convention in Python you can use _ as the name for a loop variable when you won't actually be referring to that variable anywhere.
  4. As you develop this into a full programme, structure code under functions.
  5. use blank lines sparingly

So:

def main():
    number_of_times = int(input("Choose the number of times you want to spam. "))
    message = input("What message do you want to spam? ")
    for _ in range(number_of_times):
        print(message)

Alternatively:

print((message + '\n') * number_of_times)
\$\endgroup\$

protected by rolfl Dec 17 '14 at 21:51

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.