Computers and Technology

Start with the following Python code. alphabet = "" test_dups = ["zzz","dog","bookkeeper","subderma toglyphic","subdermatoglyphics"] test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"] # From Section 11.2 of: # Downey, A. (2015). Think Python: How to think like a computer scientist. Needham, Massachusetts: Green Tree Press. def histogram(s): d = dict() for c in s: if c not in d: d[c] = 1 else: d[c] += 1 return d Copy the code above into your program but write all the other code for this assignment yourself. Do not copy any code from another source. Part 1 Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False. Implement has_duplicates by creating a histogram using the histogram function above. Do not use any of the implementations of has_duplicates that are given in your textbook. Instead, your implementation should use the counts in the histogram to decide if there are any duplicates. Write a loop over the strings in the provided test_dups list. Print each string in the list and whether or not it has any duplicates based on the return value of has_duplicates for that string. For example, the output for "aaa" and "abc" would be the following. aaa has duplicates abc has no duplicates Print a line like one of the above for each of the strings in test_dups. Part 2 Write a function called missing_letters that takes a string parameter and returns a new string with all the letters of the alphabet that are not in the argument string. The letters in the returned string should be in alphabetical order. Your implementation should use a histogram from the histogram function. It should also use the global variable alphabet. It should use this global variable directly, not through an argument or a local copy. It should loop over the letters in alphabet to determine which are missing from the input parameter. The function missing_letters should combine the list of missing letters into a string and return that string. Write a loop over the strings in list test_miss and call missing_letters with each string. Print a line for each string listing the missing letters. For example, for the string "aaa", the output should be the following. aaa is missing letters If the string has all the letters in alphabet, the output should say it uses all the letters. For example, the output for the string alphabet itself would be the following. uses all the letters Print a line like one of the above for each of the strings in test_miss. Submit your Python program. It should include the following. The provided code for alphabet, test_dups, test_miss, and histogram. Your implementation of the has_duplicates function. A loop that outputs duplicate information for each string in test_dups. Your implementation of the missing_letters function. A loop that outputs missing letters for each string in test_miss. Also submit the output from running your program. Your submission will be assessed using the following Aspects. Does the program include a function called has_duplicates that takes a string parameter and returns a boolean? Does the has_duplicates function call the histogram function? Does the program include a loop over the strings in test_dups that calls has_duplicate on each string? Does the program correctly identify whether each string in test_dups has duplicates? Does the program include a function called missing_letters that takes a string parameter and returns a string parameter? Does the missing_letters function call the histogram function? Does the missing_letters function use the alphabet global variable directly? Does the program include a loop over the strings in test_miss that calls missing_letters on each string? Does the program correctly identify the missing letters for each string in test_miss, including each string that "uses all the letters"?

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 19:10, sammigrace5820
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 1
image
Computers and Technology, 23.06.2019 10:00, uwunuzzles
How do i delete my account on this because i didn't read this agreements and also i put age at xd
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, DSUDLER5555
Write a program that prints the day number of the year, given the date in the form month-day-year. for example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. the program should check for a leap year. a year is a leap year if it is divisible by 4, but not divisible by 100. for example, 1992 and 2008 are divisible by 4, but not by 100. a year that is divisible by 100 is a leap year if it is also divisible by 400. for example, 1600 and 2000 are divisible by 400. however, 1800 is not a leap year because 1800 is not divisible by 400.
Answers: 3
image
Computers and Technology, 24.06.2019 09:50, trenrain
Create a string list. 2. use console. readline() to collect values of firstname, lastname, street, city, state, zip, save them to list. 3. write a simple linq statement, call method uppercasewords() to change first letter to uppercase. 4. create a foreach statment to display the information. public static string uppercasewords(string value) { char[] array = value. tochararray(); if (array. length > = 1) { if (char. islower(array[0])) { array[0] = char. toupper(array[0]); } } for (int i = 1; i < array. length; i++) { if (array[i - 1] == ' ') { if (char. islower(array[i])) { array[i] = char. toupper(array[i]); } } } return new string(array);
Answers: 3
Do you know the correct answer?
Start with the following Python code. alphabet = "" test_dups = ["zzz","dog","bookkeeper","subderma...

Questions in other subjects:

Konu
Advanced Placement (AP), 03.02.2020 02:57
Konu
History, 03.02.2020 02:58