Pascals triangle with recursion

ساخت وبلاگ

Vote count: 0

Okay can someone tell me if my current code is even possible. I have to create pascals triangle with an input WITHOUT using any loops. I am bound to recursion.

Ive spent 3 days on this, and this is the best output that I can come up with. its driving me INSANE

def pascal(curlvl,newlvl,tri): if curlvl == newlvl: return "" else: tri.append(tri[curlvl]) print(tri) return pascal(curlvl+1,newlvl,tri)
def triLvl(): msg = "Please enter the number of levels to generate:" triheight = int(input(msg)) if triheight < 1: print("n Sorry, the number MUST be positiven Please try again.") return triLvl() else: return triheight
def main(): triangle = [1] curlvl = 0 print("Welcome to the Pascal's triangle generator.") usrTri = triLvl() print(triangle) pascal(curlvl,usrTri,triangle)
main()
asked 1 min ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 249 تاريخ : شنبه 9 ارديبهشت 1396 ساعت: 2:54