You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
870 B

  1. import grpc
  2. import calculator_pb2 as service
  3. import calculator_pb2_grpc as stub
  4. import random
  5. def Add(a, b):
  6. args = service.Request(a=a, b=b)
  7. response = stub.Add(args)
  8. print(f"{a} + {b} = {response.ans}")
  9. def Substract(a, b):
  10. args = service.Request(a=a, b=b)
  11. response = stub.Substract(args)
  12. print(f"{a} - {b} = {response.ans}")
  13. def Multiply(a, b):
  14. args = service.Request(a=a, b=b)
  15. response = stub.Multiply(args)
  16. print(f"{a} * {b} = {response.ans}")
  17. def Divide(a, b):
  18. args = service.Request(a=a, b=b)
  19. response = stub.Divide(args)
  20. print(f"{a} / {b} = {response.ans}")
  21. if __name__ == '__main__':
  22. with grpc.insecure_channel('localhost:1234') as channel:
  23. stub = stub.CalculatorStub(channel)
  24. Add(10, 2)
  25. Substract(10, 2)
  26. Multiply(10, 2)
  27. Divide(10, 2)
  28. Divide(10, 0)