Advertisement
SimeonTs

SUPyF Functions - 03. Printing Triangle

Jun 15th, 2019
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. """
  2. Functions and Debugging
  3. Проверка: https://judge.softuni.bg/Contests/Compete/Index/922#2
  4.  
  5. 03. Printing Triangle
  6.  
  7. Условие:
  8. 03. Printing Triangle
  9. Create a function for printing triangles as shown below:
  10. Examples
  11. Input:
  12. 3
  13. Output:
  14. 1
  15. 1 2
  16. 1 2 3
  17. 1 2
  18. 1
  19.  
  20. Input:
  21. 4
  22. Output:
  23. 1
  24. 1 2
  25. 1 2 3
  26. 1 2 3 4
  27. 1 2 3
  28. 1 2
  29. 1
  30. """
  31.  
  32. num = int(input())
  33.  
  34.  
  35. def triangle():
  36.     for i in range(1, num + 1):
  37.         for j in range(1, i + 1):
  38.             print(f"{j}", end=" ")
  39.         print()
  40.     for i in range(num - 1, 0, -1):
  41.         for j in range(1, i + 1):
  42.             print(f"{j}", end=" ")
  43.         print()
  44.  
  45.  
  46. triangle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement