1
\$\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\$

1 Answer 1

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\$
0

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