Sale!

CS-521 Homework Assignment 4 solution

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (3 votes)

CS-521 Homework Assignment 4
Programming Problems
The following includes concepts taught in Chapter 7
4.1 Write a python program to solve the following:
a. Create a constant list with the integers from 55 to 5, but only every 10th number (see example).
• Set this up using the python range function
b. Generate a new list with same number of elements as the original list such that each integer in the
new list is the sum of its nearest neighbors and itself from the original list.
• The integers at the beginning and end of the list only have one nearest neighbor
c. Print both lists with descriptions. Your code should be able to work with an integer list of any size.
Example of Output:
Input List: [55, 45, 35, ]
Result List: [100, 135, ]
The following includes concepts taught in Chapter 9
4.2: Write the following python program.
a. Assign a sentence of at least 15 characters into a string constant
b. Perform analysis that counts the number of each letter and saves the result into a dictionary
• Count letters ignoring case. So ‘a’ and ‘A’ are both counted as ‘A’
• The letters are the keys, and the counts are the values
• Find the letter(s) that appears most frequently by evaluating the dictionary counts
c. Write print statements with appropriate descriptions for the items calculated in step ‘b’.
• Format print using the following examples.
• The printed dictionary must be sorted alphabetically
• Need to handle the cases of one most frequent letter vs. multiple letters.
Example Output #1
The string being analyzed is: “WAS IT A RAT I SAW?”
1. Dictionary of letter counts: {‘A’: 4, ‘I’: 2, ‘R’: 1, ‘S’: 2, ‘T’: 2, ‘W’: 2}
2. Most frequent letter “A” appears 4 times.
Example Output #2
The string being analyzed is: “Wwwas it a rat I saw?”
1. Dictionary of letter counts: {‘A’: 4, ‘I’: 2, ‘R’: 1, ‘S’: 2, ‘T’: 2, ‘W’: 4}
2. Most frequent letters [‘A’, ‘W’] appear 4 times.
CS-521 Homework Assignment 4
3
4.3 Write a python program that merges two lists into a dictionary as described below
a. Create 2 constant lists. One with first names and another of last names.
b. Validate that the last name list is the same size or larger than the first name list
• If not, exit with an error message.
c. Use zip function to create a dictionary with the last names as keys and the first names as values
• If there are more last names than first names, set the missing first names to None (not a string)
d. Print the input lists and generated dictionary with appropriate descriptions.
Example of Output:
First Names: [‘Jane’, ‘John’]
Last Names: [‘Doe’, ‘Deer’, ‘Black’]
Name Dictionary: {‘Doe’: ‘Jane’, ‘Deer’: ‘John’, ‘Black’: None}
4.4: Using MY_DICT = {a’:15, ‘c’:18, ‘b’:20}, write a program to:
a. calculate and print all the keys as a list.
b. calculate and print all the values as formatted comma separated data (not as a list).
c. print all the keys and values pairs as formatted data (not as a dictionary).
d. sort in ascending order by key and print a list of tuples for all the keys and values pairs
e. sort in ascending order by value and print as formatted data all the keys and values pairs
Output must look as follows (obviously, without any data being hard-coded):
a. Keys: [‘a’, ‘c’, ‘b’]
b. Values: 15, 18, 20
c. Key value pairs: a: 15, c: 18, b: 20
d. Key value pairs ordered by key: [(‘a’, 15), (‘b’, 20), (‘c’, 18)]
e. Key value pairs ordered by value: a: 15, c: 18, b: 20
CS-521 Homework Assignment 4
4
4.5: Create a program that:
a. creates a constant dictionary with keys for the characters ‘1234567890-.’ and values that
represent these characters as words.
• For the decimal point, use ‘point’ as the value
• For the negative sign, use ‘negative’ as the value
b. inside of an infinite loop
• prompts a user for a number with an appropriate description
• validates that a number was entered
 if valid – break out of the loop
 otherwise print error message and stay in loop to reprompt
c. convert the validated number to words using the dictionary created in step ‘a’.
d. print the converted number words with an appropriate description
Notes:
• The program must only have one input function and work for any size number.
• If the user enters commas, tell them to try again without the commas.
Example Output #1
Enter a number: 123
As Text: One Two Three
Example Output #2
Enter a number: -123
As Text: Negative One Two Three
Example Output #3
Enter a number: 1234.76
As Text: One Two Three Four Point Seven Six
Example Output #4 – invalid Input
Enter a number: 1,000
Please try again without entering commas.
Enter a number: 1 thousand
“1 thousand” is not a valid number. Please try again
Enter a number: 1000.00
As Text: One Zero Zero Zero Point Zero Zero
Where to submit?
Click Assignments in the Navigation Area and then click on the title of the assignment to enter the submission
area and upload the zip file with your response.