Write function preceding that takes a single character

Assignment Help Python Programming
Reference no: EM132356271

Question

Problem 1: Message

Coder

For parts 1 and 2 you will need to use the functions 2 you will need to use the functions 2 you will need to use the functions 2 you will need to use the functions 2 you will need to use the functions 2 you will need to use the functions 2 you will need to use the functions 2 you will need to use the functions ord and chr.

ord takes a character as an argument and returns its ASCII integer equivalent. For example:

ord('a') returns 97

ord('A') returns 65

chr takes an integer as an argument and returns the ASCII character equivalent to it. For example:

chr(97)(97) returns 'a'

chr(65)(65) returns 'A'

Note also that the entire character set has an ordering defined on it. So, the characters a to z are in increasing order (a < b < ... <y < z) and so are the characters A to Z (A < B < ... < Y < Z).

Part 1:

Write function preceding that takes a single character as an input and returns a code for that character. The coding scheme is as follows:

if the character is 'a', then the code for the character is 'z'

if the character is 'A', then the code for the character is 'Z'

if the character is between 'b' and 'z', then the code for the character is the letter that precedes it. For example, the code for 'b' is 'a', the code for 'c' is 'b' and the code for 'z' is 'y'

if the character is between 'B' and 'Z', then the code for the character is the letter that precedes it. For example, the code for 'B' is 'A', the code for 'C' is 'B' and the code for 'Z' is 'Y'

if the character is anything else, then the code for the character is the character itself. For example, the code for '!' is '!', the code for ' ' is ' ' (space is space), etc.

preceding('a') returns 'z'

x='!'

preceding(x) returns '!'

part 2:

Write function succeeding that takes a single character as an input and returns a code for that character. The coding scheme is as follows:

if the character is 'z', then the code for the character is 'a'

if the character is 'Z', then the code for the character is 'A'

if the character is between 'A' and 'Y', then the code for the character is the letter that succeeds it. For example, the code for 'A' is 'B', the code for 'B' is 'C' and the code for 'Y' is 'Z'A' and 'Y', then the code for the character is the letter that succeeds it. For example, the code for 'A' is 'B', the code for 'B' is 'C' and the code for 'Y' is 'Z'

if the character is between 'a' and 'y', then the code for the character is the letter that succeeds it. For example, the code for 'a' is 'b', the code for 'b' is 'c' and the code for 'y' is 'z'a' and 'y', then the code for the character is the letter that succeeds it. For example, the code for 'a' is 'b', the code for 'b' is 'c' and the code for 'y' is 'z'

if the character is anything else, then the code for the character is the character itself. For example, the code for '!' is '!', the code for ' ' is ' ' (space is space), etc.

succeeding('a') returns 'b'

x='!'

succeeding(x) returns '!'

part 3:

Write function message_coder that takes two arguments - a string and a function - and returns a coded message that uses the function for coding each character in the string.

For example:

message_coder('hello dolly zebra!',preceding) returns 'gdkkn cnkkx ydaqz!'

message_coder('hello dolly zebra!',succeeding) returns 'ifmmp epmmz afcsb!'

Problem 2

Write function word_distribution that takes as inputs a string and an optional word_list as arguments and returns a dictionary containing the frequency of each word in the text, or of each word in the word_list if it is included in the function call. For example if the argument to the function is: example if the argument to the function is:

text_string = "Hello. How are you? Please say hello if you don't love me!"

print(word_distribution(text_string)) should print

{'hello': 2, 'how':1, 'are':1, 'you':2,'please':1, "don't": 1 ...}

If the word_list is provided then the function should return the count of words in the word_list and ignore all other words in the text. word_list is the set of words that should be counted. (The value for word_list should default to None.)

text_string = 'I came, I saw, I conquered!'

word_distribution(text_string,word_list=['I','saw','Britain'])

returns

{'i':3,'saw':1,'britain':0}

Make sure that you exclude all punctuation from your count and that your count ignores case. Thus, Hello and hello are the same word in the above example. The . ? and ! are all ignored. But the apostrophe in don't doesn't count and don't is treated as a single word.

Notes:

word.split() splits a string on spaces and returns a list. Note that this will concatenate punctuation with words. For the above example, you will get:

['Hello.','How','are','you?',...]

Reference no: EM132356271

Questions Cloud

Discuss the problem related to vpn service : Using the Internet, locate TWO companies that provide VPN services. Compare the TWO different services offered. Include their services, pricing, and make.
Create a program to calculate the body mass index bmi : Create a program to calculate the body mass index BMI for a person using the person's height in inches and weight in pounds.
Industry analysis and financial analysis : Industry Analysis. Business SWOT Analysis. Detailed Financial Analysis Please explain why? and analyze, and discuss in great detail EACH Bullet Point ...
Describe the three steps in designing process layouts : APA format is required, using the template provided in the course. References for all questions should be listed at the end of the paper in the References.
Write function preceding that takes a single character : Write function preceding that takes a single character as an input and returns a code for that character. Write function succeeding that takes single character.
Define principles for protecting national infrastructure : The course textbook proposed ten basic design and operation principles for protecting national infrastructure. Please list all 10, and then explain two.
Explain the verification and validation of package diagram : Perform and explain the verification and validation walk-through of the package diagram. Create a set of invariants for attributes and relationships.
Prompt for the rate of return on an investment and calculate : Write a quick calculator that prompts for the rate of return on an investment and calculates how many years it will take to double your investment.
What are limitations associated with quantum cryptography : What are the limitations or problems associated with quantum cryptography? What features or activities will affect both the current and future developments.

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