zyulfi

Filled_or_empty_square

May 31st, 2025
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | Source Code | 0 0
  1. # Задача 3
  2. # Напишете функция, която извежда празен или запълнен квадрат от някакъв символ.
  3. # Функцията приема като параметри: дължината на страната на квадрата, символа и променлива от булев тип:
  4. #  ако тя е True, квадратът е запълнен;
  5. #  ако е False, квадратът е празен.
  6.  
  7. def filled_or_empty_square (size, symbol, bool):
  8.     if bool == "true":
  9.         for row in range(1, size + 1):
  10.             print(f"{symbol}", end=" ")
  11.             for col in range(1, size):
  12.                 print(f"{symbol}", end=" ")
  13.             print()
  14.     elif bool == "false":
  15.         print(f"{symbol} " * size)
  16.         for row in range(1, size - 1):
  17.             print(f"{symbol}", end=" ")
  18.             for col in range(1, size - 1):
  19.                 print(" ", end=" ")
  20.             print(f"{symbol}", end=" ")
  21.             print()
  22.         print(f"{symbol} " * size)
  23.     else:
  24.         print("Please enter true or false for boolean value:")
  25.     return size, symbol, bool
  26.  
  27. size_suqare = int(input("Please enter an integer for the length of the square: "))
  28. symbol_suqare = input("Please enter symbol for square: ")
  29. boolean_suqare = input("Please enter boolean value for square: ").lower()
  30.  
  31. print(filled_or_empty_square(size_suqare, symbol_suqare, boolean_suqare))
Advertisement
Add Comment
Please, Sign In to add comment