calculate.py 688 B

123456789101112131415161718192021222324252627282930313233
  1. import circle
  2. import square
  3. figs = ['circle', 'square']
  4. funcs = ['perimeter', 'area']
  5. sizes = {}
  6. def calc(fig, func, size):
  7. assert fig in figs
  8. assert func in funcs
  9. result = eval(f'{fig}.{func}(*{size})')
  10. print(f'{func} of {fig} is {result}')
  11. if __name__ == "__main__":
  12. func = ''
  13. fig = ''
  14. size = list()
  15. while fig not in figs:
  16. fig = input(f"Enter figure name, avaliable are {figs}:\n")
  17. while func not in funcs:
  18. func = input(f"Enter function name, avaliable are {funcs}:\n")
  19. while len(size) != sizes.get(f"{func}-{fig}", 1):
  20. size = list(map(int, input("Input figure sizes separated by space, 1 for circle and square\n").split(' ')))
  21. calc(fig, func, size)