Docsity

Programming Assignment Unit 7, Assignments of Programming Languages

Toggle sidebar
bg1
Programming Assignment 7
Alphabet = “abcdefghijklmnopqrstuvwxyz”
Test_dups = [“zzz”, “dog”, “bookkeeper”, “subdermatoglyphic”, “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
Def has_duplicates(s):
# Return False if each letter in s is not distinct
Return len(histogram(s)) != len(s)
pf2

Partial preview of the text

Download Programming Assignment Unit 7 and more Assignments Programming Languages in PDF only on Docsity!

Programming Assignment 7 Alphabet = “abcdefghijklmnopqrstuvwxyz” Test_dups = [“zzz”, “dog”, “bookkeeper”, “subdermatoglyphic”, “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 Def has_duplicates(s):

Return False if each letter in s is not distinct

Return len(histogram(s)) != len(s)

Def missing_letters(s): H = histogram(s) Rv = ‘’

Loop over letters in alphabet, if the letter is not in the histogram then

append to the return string.

For c in alphabet: If c not in h: Rv = rv + c Return rv

Loop over test strings as required.

For s in test_miss: Miss = missing_letters(s) If miss: Print(f”{s} is missing letters {miss}.”) Else: Print(f”{s} uses all the letters.”)