In: Computer Science
In python can you fix the error in the line where it says message = input("Input a lowercase sentence: ")
this is the error message I get after running the program and inputing a lowercase sentence
Input a lowercase sentence:hello hi
MM§MTraceback (most recent call last):
MM§M File "client.py", line 14, in <module>
MM§M message = input("Input a lowercase sentence:")
MM§M File "<string>", line 1
MM§M hello hi
MM§M ^
MM§MSyntaxError: unexpected EOF while parsing
from socket import *
# server name
serverName = 'localhost'
# server port number
serverPort = 5000
# creating udp socket
clientSocket = socket(AF_INET, SOCK_DGRAM)
# infinite loop
while True:
# getting input from the user
message = input("Input a lowercase sentence:
")
# if the user types "quit" then break from
the loop
if message =="quit" or message =="Quit":
# closing the
connection
clientSocket.close()
# break from the
loop
break
# sending the data to the server
clientSocket.sendto(message.encode(),
(serverName, serverPort))
# receiving data from the user
modifiedMessage, serverAddress =
clientSocket.recvfrom(2048)
# printing the received data
print(modifiedMessage.decode())
from socket import *
# server name
serverName = 'localhost'
# server port number
serverPort = 5000
# creating udp socket
clientSocket = socket(AF_INET, SOCK_DGRAM)
# infinite loop
while True:
# getting input from the user
message = raw_input("Input a lowercase sentence: ")
# if the user types "quit" then break from the loop
if message =="quit" or message =="Quit":
# closing the connection
clientSocket.close()
# break from the loop
break
# sending the data to the server
clientSocket.sendto(message.encode(), (serverName, serverPort))
# receiving data from the user
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
# printing the received data
print(modifiedMessage.decode())
Explaination:
You can use raw_input() instead of input() to take the user input.
raw_input() reads the input and returns the string. Return type of
raw_input() is always string whereas return type of input()
function can be different from string.