Advertisement
mbratanov

Triangle - Recursion

Oct 7th, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. def print_numbers(curr_num):
  2.     if curr_num == 0:
  3.         return
  4.     print_numbers(curr_num - 1)
  5.     print(curr_num, end="")
  6.  
  7.  
  8. def print_pattern(n, curr_num=1):
  9.     print_numbers(curr_num)
  10.     print()
  11.     if curr_num < n:
  12.         print_pattern(n, curr_num + 1)
  13.  
  14.     if curr_num > 1:
  15.         print_numbers(curr_num - 1)
  16.         print()
  17.  
  18.  
  19. n = int(input())
  20. print_pattern(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement