Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import pi
- figure = input()
- area = 0
- if figure == 'square':
- side = float(input())
- area = side * side
- elif figure == 'triangle':
- lenght = float(input())
- hight = float(input())
- area = lenght * hight / 2
- elif figure == 'circle':
- radius = float(input())
- area = radius * radius * pi
- elif figure == 'rectangle':
- first_side = float(input())
- second_side = float(input())
- area = first_side * second_side
- print(f'{area:.3f}')
- ДРУГО РЕШЕНИЕ:
- from math import pi
- figure = input()
- if figure == 'square':
- print(f'{float(input()) ** 2:.3f}')
- elif figure == 'triangle':
- print(f'{float(input()) * float(input()) / 2:.3f}')
- elif figure == 'circle':
- print(f'{float(input()) ** 2 * pi:.3f}')
- elif figure == 'rectangle':
- print(f'{float(input()) * float(input()):.3f}')
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- from math import pi
- figure = input()
- area = float(input()) ** 2 if figure == 'square' \
- else float(input()) ** 2 * pi if figure == 'circle' \
- else float(input()) * float(input()) / 2 if figure == 'triangle' \
- else float(input()) * float(input()) if figure == 'rectangle' else 0
- print(f'{area:.3f}')
- РЕШЕНИЕ С IF-ELSE И ТЕРНАРЕН ОПЕРАТОР:
- from math import pi
- figure = input()
- if figure in ('square', 'circle'):
- print(f'{float(input()) ** 2 * (pi if figure == "circle" else 1):.3f}')
- elif figure in ('triangle', 'rectangle'):
- print(f'{float(input()) * float(input()) / (2 if figure == "triangle" else 1):.3f}')
- РЕШЕНИЕ С РЕЧНИК:
- from math import pi
- figure = input()
- a = float(input())
- b = 0
- if figure in ('triangle', "rectangle"):
- b = float(input())
- area = {'square': a ** 2,
- 'triangle': a * b / 2,
- 'circle': a ** 2 * pi,
- 'rectangle': a * b
- }
- print(f'{area[figure]:.3f}' if figure in area else '')
- РЕШЕНИЕ С ФУНКЦИИ:
- from math import pi
- def figures(figure):
- if figure == 'square':
- return square()
- elif figure == 'triangle':
- return triangle()
- elif figure == 'circle':
- return circle()
- elif figure == 'rectangle':
- return rectangle()
- def square():
- return float(input()) ** 2
- def triangle():
- return float(input()) * float(input()) / 2
- def circle():
- return float(input()) ** 2 * pi
- def rectangle():
- return float(input()) * float(input())
- print(f'{figures(input()):.3f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement