-4

Basically, I want to use a for loop inside of a printed statement, basically the user inputs the word, and it prints that out after a variable. Something like this

If they input the word "Pizza" it will output:

I like P
I like i
I like z
I like z
I like a

PIZZA Exactly like that.

I've already tried a slow way, using print(name[0]) and print(name[1]) and so on but I realized there would be errors if the inputted text wasn't exactly 5 characters.

ShivaGaire
  • 2,283
  • 1
  • 20
  • 31
OpBanana
  • 53
  • 4
  • 1
    Hey OpBanana, Look for List comprehensions in Python – Chitrank Dixit Aug 08 '19 at 04:25
  • 2
    `print(' '.join('I like %s' % i for i in 'Pizza'))`? – Chris Aug 08 '19 at 04:29
  • https://www.pythonforbeginners.com/system/python-sys-argv – TomK Aug 08 '19 at 04:29
  • 1
    Welcome to Stack Overflow! Please note that in order to keep SO full of amazing answers to interesting problems, some other problems, like homework, get downvoted, closed and removed. – Dima Tisnek Aug 08 '19 at 04:39
  • 1
    Asking homework questions [should be OK](https://meta.stackoverflow.com/a/334823/2745495) as long as the OP made some attempt at researching and solving the problem on their own, and they asked a specific problem or a specific portion of the code, rather than asking how to do the entire thing. – Gino Mempin Aug 08 '19 at 05:06

1 Answers1

0
texts = ["PIZZA", "RED WINE"]
for i in range(len(texts)):
    text = "".join(texts[i].split())
    print(' '.join('I like %s' % i for i in text))

In case you need another word except the PIZZA.

mk_
  • 112
  • 1
  • 9
  • No need for 2 list comprehensions. Loop over each word (`for txt in texts`) and then loop over each character of the word (`print(' '.join('I like %s' % c for c in txt))`) – Gino Mempin Aug 08 '19 at 05:03
  • My mistake. I think it should add the "PIZZA" along with the word. – mk_ Aug 08 '19 at 05:16