Рекурсивный подход к печати треугольников ⇐ Python
-
Anonymous
Рекурсивный подход к печати треугольников
I have been learning concepts like recursion lately and tried attempting old programs in python that I solved using an iterative approach for example printing triangular patterns, for example:
* ** *** **** ***** but the output I get is:
***** **** *** ** * None def itriangle(x): if x==0: return print("*",end="") itriangle(x-1) def jtriangle(y): if y==0: return itriangle(y) print() jtriangle(y-1) print(jtriangle(5)) this is the code I wrote, Firstly I get this triangle inverted and secondly I get a "None" return as the last line. How to fix this?
Edit: I have fixed the None that I was getting , that was just a typo on my side but now the problem (The main issue) is that I am getting an inverted triangle and dont know how to fix it. any help will be much appreciated.
Источник: https://stackoverflow.com/questions/781 ... n-printing
I have been learning concepts like recursion lately and tried attempting old programs in python that I solved using an iterative approach for example printing triangular patterns, for example:
* ** *** **** ***** but the output I get is:
***** **** *** ** * None def itriangle(x): if x==0: return print("*",end="") itriangle(x-1) def jtriangle(y): if y==0: return itriangle(y) print() jtriangle(y-1) print(jtriangle(5)) this is the code I wrote, Firstly I get this triangle inverted and secondly I get a "None" return as the last line. How to fix this?
Edit: I have fixed the None that I was getting , that was just a typo on my side but now the problem (The main issue) is that I am getting an inverted triangle and dont know how to fix it. any help will be much appreciated.
Источник: https://stackoverflow.com/questions/781 ... n-printing