0

I will Show you a simple demonstration of what I want to accomplish:

import numpy as np
word = input("Enter a word : "+ ' ')
pxlength = (len(word))
word= " ".join(word)
m = (np.str_(word))
for g in range(5):
     print(m)

if I Enter my name- Eitan it will print:

e i t a n
e i t a n
e i t a n
e i t a n
e i t a n

The thing that I want is a variable that represent the output,we will call him e, im trying to get to this: print(e) and it will print:

    e i t a n
    e i t a n
    e i t a n
    e i t a n
    e i t a n

I tried to look for this in so much places but I probably dont know how and what exactly to search.. I know that this is a very silly qu but I really need help, tnx.

Eitan
  • 1
  • I don't understand the issue, is it the missing indentation? – Sayse Nov 22 '21 at 14:11
  • 1
    You don't need that `m = (np.str_(word))`. Anyway, if you just want some white space in front of the string then just do `e = ' ' + word`. – Abdur Rakib Nov 22 '21 at 14:14

3 Answers3

2

You can do something like that

e = f'{word}\n' * 5
print(e)
Guy
  • 46,488
  • 10
  • 44
  • 88
0

What you are trying to achieve is more complicated than it seems and probably means the problem itself is flawed - you shouldn't need to use print output further in your code. That being said, it is possible to achieve by capturing stdout and stderr, as described here: https://stackoverflow.com/a/40417352/9296093

matszwecja
  • 6,357
  • 2
  • 10
  • 17
  • yeah I taught it was wayyyy easier ... ty for the link I would definitely try to understand and use it. – Eitan Nov 22 '21 at 14:19
  • I'd say don't try to use it. Try to write your program in such a way that you don't need to do such weird things. – matszwecja Nov 22 '21 at 14:21
  • Simplest solution: Instead of printing in each iteration of a loop, create a variable that add your word to on each execution. After the loop is finished, you print everything at once and then also return the string as value. – matszwecja Nov 22 '21 at 14:23
0

try this:

word = input("Enter a word : "+ ' ')
word_sep = ' '.join(word)
e = '\n'.join([word_sep]*5)
print(e)
asiloisad
  • 41
  • 4