Advertisement
SimeonTs

SUPyF Functions - 04. Draw a Filled Square

Jun 15th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. """
  2. Functions and Debugging
  3. Проверка: https://judge.softuni.bg/Contests/Compete/Index/922#3
  4.  
  5. 04. Draw a Filled Square
  6.  
  7. Условие:
  8. Draw at the console a filled square of size n like in the example:
  9. Examples
  10. Input:
  11. 4
  12. Output:
  13. --------
  14. -\/\/\/-
  15. -\/\/\/-
  16. --------
  17.  
  18. Hints
  19. 1.  Read the input
  20. 2.  Create a function which will print the top and the bottom rows (they are the same).
  21. Don’t forget to give it a descriptive name and to give it as a parameter some length
  22. 3.  Create the function which will print the middle rows.
  23. 4.  Use the functions that you've just created to draw a square.
  24. """
  25.  
  26.  
  27. num = int(input())
  28.  
  29.  
  30. def top_and_bottom():
  31.     for i in range(num * 2):
  32.         print(f"-", end="")
  33.     print()
  34.  
  35.  
  36. def filling():
  37.     print(f"-", end="")
  38.     for i in range(int(((num * 2) - 2) / 2)):
  39.         print(f"\/", end="")
  40.     print(f"-", end="")
  41.     print()
  42.  
  43.  
  44. def square():
  45.     top_and_bottom()
  46.     for i in range(num - 2):
  47.         filling()
  48.     top_and_bottom()
  49.  
  50.  
  51. square()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement