Reputation: 49
I'm beginner on python, and i tried to repeat my python command from line 3 until line 7 on this code
print("Hello")
print("World")
print("Foo")
print("Foo")
print("Foo")
print("Foo")
print("Foo")
but i don't want to repeat that foo for 4 times, i want to make it shorter like this
print("Hello")
print("World")
print("Foo")
print ln 3 * 4 times again
but it did't work(yeah i know it supposed to be not worked)
to someone who knows or can give the solution please help me, thanks!
Upvotes: 0
Views: 69
Reputation: 302
Use a loop to repeat the command. Try:
print("Hello")
print("World")
for x in range(5):
print("Foo")
Upvotes: 3
Reputation: 1561
The answer from Reddy Lutonadio is correct, but the code below is a little shorter and teaches some concepts about Python Lists:
for s in ["Hello", "World"] + ["Foo"]*5:
print(s)
Or, even shorter:
print("\n".join(["Hello", "World"] + ["Foo"]*5))
Upvotes: 2