1
The function print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
has the argument end
and by default end='\n'
, I know I change for end=' '
will print in the same line.
But I am advancing my knowledge in Python and thought about an activity that I need to 'print' in the same line a mathematical formula side by side, example:
1 2 3
+1 +2 +3
-- -- --
Has some form of 'printar' of this formula above using a for
more or less in this example "1 n+1 n-" or to achieve this effect I need to create an array and use two for (Rows,Columns) to 'print' the result I want?
I performed a test code. See here:
my_list=(["1 + 1","2 + 2","3 + 3"])
for i in my_list:
print(i, end=" | ")
print("\n\n\n")
for j in my_list:
print(f" {j.split()[0]}\n{j.split()[1]}{j.split()[2]}\n--", end="")
print("\n\n\n")
print("""
------Espectativa-----
1 2 3
+1 +2 +3
-- -- --
""")
I want to understand if it is possible to do as an example.
For this specific case it could be something like this: https://ideone.com/S12uj7 - of course if the expressions can vary in size, have numbers with more than 1 digit, etc, then you would have to adapt
– hkotsubo
It worked as expected. I will try to understand what happens and in each part of the code to improve my knowledge. Thank you!
– rochaa