#!/usr/bin/python3

import socket		 	                      
import sys


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

from_user   = sys.argv[1]
split       = from_user.split(':')
host        = str(split[0])                           
port        = int(split[1])


s.connect((host, port))                           
                           
print("Connected to :",from_user)
initial_msg = s.recv(1024).decode()
print("\n", initial_msg)
s.send("OK\n".encode())

while(True):
	U=s.recv(1024).decode()
	print(U)
	X=U.split()
	if len(X) > 1:
		if X[0] == "add":
			m = int(X[1])+int(X[2])
			m1=str(m)+"\n"
			s.send(m1.encode())
			print("result is ",str(m) )
           
		elif X[0] == "sub":
			n = int(X[1])-int(X[2])
			b1=str(n)+"\n"
			s.send(b1.encode())
			print("result is ", str(n))
          
		elif X[0] == "mul":
			p = int(X[1])*int(X[2])
			m1=str(p)+"\n"
			s.send(m1.encode())
			print("result is ", str(p))
          
		elif X[0] == "div":
			o = int(X[1])/int(X[2])
			m1=str(o)+"\n"
			s.send(m1.encode())   
			print('result is %8.8g' %o)
			
		elif X[0] == "fadd":
			fm = float(X[1])+float(X[2])
			m1=str(fm)+"\n"
			s.send(m1.encode())
			print('result is %8.8g' %fm)
          
		elif X[0] == "fsub":
			fn = float(X[1])-float(X[2])
			m1=str(fn)+"\n"
			s.send(m1.encode())
			print('result is %8.8g'%fn)
            
		elif X[0] == "fmul":
			fp = float(X[1])*float(X[2])
			m1=str(fp)+"\n"
			s.send(m1.encode())
			print('result is %8.8g' %fp)
            
		elif X[0] == "fdiv":
			fo = float(X[1])/float(X[2])
			m1=str(fo)+"\n"
			s.send(m1.encode())
			print('result is %8.8g' %fo)
      		
		response = s.recv(1024).decode()
		print (response)
	break

        
s.close
