Write a function that is given the name of the text file

Assignment Help Python Programming
Reference no: EM132356960

The De­slang­ifier

In this assignment, you are writing a program that converts common texting abbreviations to English words to allow people like yours truly can understand. For the assignment, you are provided with a .txt file, called TextToEnglish.txt, that provides the abbreviations and their English translation. The file contains G­Rated translations only. The txt file has comma separated values that list the key as the first item, a comma to separate the key from the value, and then the value.

For this assignment, you need to submit one file, where LastName is your last name. Please include comments in your code that explain what your code is doing. The comments should also include your name, recitation TA, and the assignment number. Each function should be commented with the functions purpose and description of the parameters.

Steps:

1. Write a function, called CreateDictionary that is given the name of the text file to be read. The function opens the given file, reads in data, and generates a dictionary. The dictionary key is the text abbreviation and the value is the English translation.

For example, one entry in your dictionary will be, ‘l8': ‘late' because one of the rows in the txt file contains ‘l8' and ‘late'. ?Your function should have one input: the name of the file to open, and one return value: the dictionary. Test your function before moving on to the next step. You can do this by defining the function and then calling it in your .py file: ?wordDictionary = CreateDictionary(filename)

2. Write a function Deslang(...) that takes two parameters, a string and a dictionary, and returns the deslanged string. Each word in the string will be replaced if it has an entry in the dictionary. Any word not in the dictionary should be copied to the results. ?deslanged = Deslang(slang, wordDictionary) ?For example, if the slang string is: "David, y r u l8"?your function should return: "David, why are you late"

3. Your main function in the .py file containing your functions, CreateDictionary, and Deslang, should do the following:

a. Call the CreateDictionary function.

b. Prompt the user for a text abbreviation and check if it is in the dictionary. If it is, print the English words associated with the abbreviation, otherwise print "Not Found". ?Your main must also allow the user to continue inputting abbreviations and printing the English meaning of those abbreviations until the user enters "quit".

c. Prompt the user for an arbitrary number of text abbreviations, separated by a space, and print a string that displays the meaning of all abbreviations (by calling the Deslang function). ?Your main must also allow the user to continue inputting sentences with abbreviations and printing the English meaning of those sentences without abbreviations until the user enters "quit".

For this assignment, will be testing your code by importing your code into our own .py files and calling your functions. We will not use your main function. Therefore, your functions for CreateDictionary and Deslang should not produce any output or require any input from user.

You can test this by creating another .py file that imports your assignment into it and has its own main function that calls your required functions.

Lists:

A list in python is an important data type. To store elements as a list, place all the elements enclosed within square brackets and separated by comma. Unlike in c++ we can have different types of elements in the same python list. Below are some of the examples of lists
myList = [] # empty list?myList = [1, 2, 3]# list of integers?myList = [1, "Hello", 3.4]# list with mixed datatypesmyList = ["csci1300", [2, 4, 6]] # nested list

Access elements in a list

To access the elements in a list we need to use the index operator [ ]. Similar to arrays in c++, python lists index starts from 0. For example, a list having 10 elements will have index from 0 to 9.

Dictionaries in Python:

A dictionary is an associative array. It is also known as hashes. Dictionaries in python have a key and value pairs; where each key is associated to a value. Keys in dictionary should be unique and the values can be of any Python data type. Due to this reason dictionaries in python are unordered key-value pairs.

In a dictionary each and every key is separated from its value by a colon (:), the elements are separated by commas, and the whole thing is enclosed in curly braces.

Deleting a Dictionary and specific elements:

To delete a element in a dictionary with a specific key we use the below command
del mydict['Name'] # remove the element with key 'Name'

To delete all the elements in a dictionary we use the below command
mydict.clear()# delete all the entries in dictTo delete the entire dictionary we use the below command
delmydict# delete the entire dictionary File I/O in Python:

The file I/O operations are similar to C++. The steps followed to open and close a file are as shown below

1) Open a file in the correct mode and store it in a file object.?2) Use this file object to modify or read from the file as required.?3) Once done with all the operations in a file , please make sure to close the file.

Recitation Activity

Write a function called countElements that counts the number of times two elements appear in a list. Your task is to ask the user to enter a list and two elements which they need to count in the list. The list and each of the elements should be inputs to a function called countElements. The function should print the count of the number of times the elements appear in the list.

Reference no: EM132356960

Questions Cloud

Create a python function which takes two arguments : Create a Python function which takes two arguments, a single character and a string of arbitrary length, and returns the number of times.
Our contemporary politics as interest group : The American Legislative Exchange Council (ALEC) is deeply embedded in our contemporary politics as an interest group.
Calculate the average of all the numbers stored in the file : Assume that a file containing a series of integers is named numbers.txt. Write a program that calculates the average of all the numbers stored in the file.
Evaluate wireless mobile communication systems : ME601 Telecommunication Modelling and Simulation - Research and analyze recent developments, and relate them to the principles of mobile network design
Write a function that is given the name of the text file : You are writing a program that converts common texting abbreviations to English words to allow people like yours truly can understand.
Our global neighborhood-explain its mission and function : Our Global Neighborhood. Explain its mission and function. Assess how issues of state sovereignty are dealt with for member countries.
Write paper on preparation of a new tourism plan or policy : Your task is to prepare a discussion paper proposing the preparation of a new tourism plan or policy to address an emerging tourism issue
How liberal and conservative would approach developing : Explain how a liberal and conservative would approach developing the US budget. Use evidence (cite sources) to support your response from assigned readings
Explain the definition and assumptions of law of demand : Explain the definition and assumptions of law of demand. Discuss also the Exceptional cases paradoxical to the law of demand

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd