I want to print name two times but in horizontal format.
Expected Output :
Gab
Gab
Output:
G
a
b
G
a
b
My Code :
name = "Gab"
total = name * 2
for gen in total:
print(gen)
CodePudding user response:
total should just be 2, and you should use range (or any other method to generate an iterable of size total):
name = input("Enter name: ")
total = 2
for gen in range(total):
print(name)
how your code failed
name = "Gab"
total = name * 2 # total is now "GabGab"
for letter in total: # now we iterate over the letters of "GabGab"
print(letter) # and print them on separated lines
CodePudding user response:
If changing only one thing your code works correctly, add this []:
(name -> [name])
name = "Gab"
total = [name] * 2
for gen in total:
print(gen)
