Question

In: Computer Science

In python can you fix the error in the line where it says message = input("Input...

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())

  

Solutions

Expert Solution

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.


Related Solutions

I'm getting an error message with this code and I don't know how to fix it...
I'm getting an error message with this code and I don't know how to fix it The ones highlighted give me error message both having to deal Scanner input string being converted to an int. I tried changing the input variable to inputText because the user will input a number and not a character or any words. So what can I do to deal with this import java.util.Scanner; public class Project4 { /** * @param args the command line arguments...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and...
(CODE IN PYTHON) Program Input: Your program will display a welcome message to the user and a menu of options for the user to choose from. Welcome to the Email Analyzer program. Please choose from the following options: Upload text data Find by Receiver Download statistics Exit the program Program Options Option 1: Upload Text Data If the user chooses this option, the program will Prompt the user for the file that contains the data. Read in the records in...
use the python language and fix the error code #Write a function called rabbit_hole. rabbit_hole should...
use the python language and fix the error code #Write a function called rabbit_hole. rabbit_hole should have #two parameters: a dictionary and a string. The string may be #a key to the dictionary. The value associated with that key, #in turn, may be another key to the dictionary. # #Keep looking up the keys until you reach a key that has no #associated value. Then, return that key. # #For example, imagine if you had the following dictionary. #This one...
in Python, Define the class called Line which represents a line with equation ?=??+? with input...
in Python, Define the class called Line which represents a line with equation ?=??+? with input slope ? and intercept ? to initialize the instances. It should include: attributes named ? and ? to represent slope and intercept. method named intersect to return the list, containing coordinates of the intersection point of two lines. support for + operator to compute the addition of two equations. The sum of two Line objects ?=?1?+?1 and ?=?2?+?2 is defined as the line ?=(?1+?2)?+?1+?2...
I keep getting the error below in zbooks. How can I fix this. Thank You JAVA...
I keep getting the error below in zbooks. How can I fix this. Thank You JAVA zyLabsUnitTest.java:14: error: cannot find symbol s = MidtermProblems.difference(75, 75); ^ symbol: method difference(int,int) location: class MidtermProblems 1 error import java.lang.Math; public class MidtermProblems { public static String difference(int a, int b) { int diff = Math.abs(a - b); String ans = "";    if (diff == 0) { ans = "EQUAL";    } else if (diff > 10) { ans = "Big Difference "...
Please fix this python script, I keep getting a return outside function error and cannot get...
Please fix this python script, I keep getting a return outside function error and cannot get it to run: def caesar(plainText, shift):     cipherText = "" for char in plainText:     newChar = ord(char) + shift     if newChar > 128:       newChar = newChar % 128     finalChar = chr(newChar)     cipherText += finalChar return cipherText text = input("Enter a message: "); s = input("Enter the distance value: "); print (caesar(text, int(s)));
using this code under, I want when the user input only letter q an error message...
using this code under, I want when the user input only letter q an error message appears that there is no second smallest, how I can do that? #include <iostream> #include <sstream> #include <vector> #include <algorithm> using namespace std; int secondSmallestNumber(vector<int> &I); int main() {    cout << "Enter the numbers in random order: (close by entering q)" << endl;    vector<int> I;    int input;    stringstream ss;    string str;    bool flag = false;    while (!flag) {        getline(cin, str);        ss.clear();        ss << str;...
In matlab please. It says that not enough arguments. How, what, and where to input? function...
In matlab please. It says that not enough arguments. How, what, and where to input? function longestword (word1,word2,word3) if strlength(word1) > strlength(word2) && strlength(word1) > strlength(word3) fprintf(word1); elseif strlength(word2) > strlength(word1) && strlength(word2) > strlength(word3) fprintf(word2); else fprintf(word3) end end
C++ Text message decoder Use getline() to get a line of user input into a string:...
C++ Text message decoder Use getline() to get a line of user input into a string: Enter text: IDK if I'll go. It's my BFF's birthday. Search the string using find() for common abbreviations and replace() them with their long form. In addition, use a for loop to iterate through each character of the string and replace any occurences of '.' with '!': Enter text: IDK if I'll go. It's my BFF's birthday. I don't know if I'll go! It's...
In Python: how can I fix the IsADirectoryError: [Errno 21] Is a directory: ??? this is...
In Python: how can I fix the IsADirectoryError: [Errno 21] Is a directory: ??? this is my code: #importing sqlite and pandas import sqlite3 import pandas as pd #goal print("Welcome! The goal of this assigment is to create a database to find meanings and synonyms for given phrases.") #Connecting database conn = sqlite3.connect("keilavaldez.db") #Creating cursor to remove existing specified tables cur = conn.cursor() #creating tables cur.execute("CREATE TABLE Synsets([SynsetID] INTEGER,[Definition] text)") cur.execute("CREATE TABLE Phrases([SynsetID] INTEGER,[phrase] text)") conn.commit() #opening and reading table...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT