Python翻译器

时间:2017-10-02 19:08:57

标签: python

尝试创建客户端服务器端应用程序,其中服务器接收输入消息并进行翻译。

import socket
portNum=6000
serverSocket=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
serverSocket.bind((socket.gethostname(),portNum))
print("The server is ready to be used")


def translator(message):
    starting = message[0]

    if starting == ("a" or "e" or "i" or "u"):
        newMessage = message + start + ay
        return newMessage
    else:
        message = message[1:] + starting + "ay"
        return message


while True:
    message,clientAddress=serverSocket.recvfrom(4096)
    newMessage= message.decode()
    translator(message)
    serverSocket.sendto(newMessage.encode(),clientAddress)

1 个答案:

答案 0 :(得分:2)

您永远不会将翻译器的输出分配给变量。尝试更改行

translator(message)

newMessage = translator(newMessage)