python - Trying to print two functions starting on the same line -


i'm trying print top half of diamond 2 helper functions, , main. code:

def top_right(size):     line = ''     nsize = size // 2 + 1     spaces = nsize - 1      num in range(1, nsize + 1):         line += str(num)         print(spaces * ' ' + line)  def top_left(size):     line = ''     nsize = size // 2 + 1      print()     num in range(2, nsize + 1):         spaces = nsize - num         line += str(num)         print(spaces * ' ' + line[::-1])  def full_diamond(size):     top_left(size), top_right(size) 

the full diamond function comes out this:

full_diamond(17)         2       32      432     5432    65432   765432  8765432 98765432         1         12         123         1234         12345         123456         1234567         12345678         123456789 

how these 2 triangles print o same line, top half of diamond?

you can use asyncio:

import asyncio  async def top_right(size):     line = ''     nsize = size//2+1     spaces = nsize-1     num in range(1, nsize+1, 1):         line+=str(num)         print(spaces* ' '+line)         await asyncio.sleep(0.001)  async def top_left(size):     line = ''     nsize = size//2+1     print()     num in range(2, nsize+1, 1):         spaces = nsize - num         line+=str(num)          print(spaces*' '+line[::-1], end='')         await asyncio.sleep(0.001)  def full_diamond(size):     loop = asyncio.get_event_loop()     tasks = [top_left(size), top_right(size)]     loop.run_until_complete(asyncio.wait(tasks)) 

this code works python 3.5 or greater


Comments