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: 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...
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
Python 3 Fix this: show the current date where the calendar field is # required library...
Python 3 Fix this: show the current date where the calendar field is # required library import tkinter as tk from tkcalendar import DateEntry import xlsxwriter # frame window = tk.Tk() window.title("daily logs") #window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=3, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window) product = tk.Entry(window) money = tk.Entry(window) # arraging barcode.grid(row=0, column=1) product.grid(row=1, column=1) money.grid(row=2, column=1) cal...
Fix this broken code? # Get our input from the command line import sys string =...
Fix this broken code? # Get our input from the command line import sys string = sys.argv[1] # Your code goes here if string 'Bingo' print('Missed') else: print('Hit!')
Telephone is a classic kids game where the first person in line is told a message....
Telephone is a classic kids game where the first person in line is told a message. That person whispers the word to the one next to them, and so on. The last person in line then announces the message as they understand it. Describe this game as a networking protocol in terms of the OSI model. Be specific, and include whatever layers you see as important. How could you change the protocol (and ruin the game) to ensure that the...
Python 3 Fix the code so i can make the window larger or smaller and the...
Python 3 Fix the code so i can make the window larger or smaller and the fields adjusts everytime according to the window size import tkinter as tk from tkcalendar import DateEntry from openpyxl import load_workbook window = tk.Tk() window.title("daily logs") # window.resizable(0,0) # labels tk.Label(window, text="Bar code").grid(row=0, sticky="W", pady=20, padx=20) tk.Label(window, text="Products failed").grid(row=1, sticky="W", pady=20, padx=20) tk.Label(window, text="Money Lost").grid(row=2, sticky="W", pady=20, padx=20) tk.Label(window, text="sold by").grid(row=3, sticky="W", pady=20, padx=20) tk.Label(window, text="Failed date").grid(row=4, sticky="W", pady=20, padx=20) # entries barcode = tk.Entry(window)...
The assignment is to build a program in Python that can take a string as input...
The assignment is to build a program in Python that can take a string as input and produce a “frequency list” of all of the wordsin the string (see the definition of a word below.)  For the purposes of this assignment, the input strings can be assumed not to contain escape characters (\n, \t, …) and to be readable with a single input() statement. When your program ends, it prints the list of words.  In the output, each line contains of a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT