Start with the following Python code. 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 Please help with Bartleby homework answered, I had received an error message for Unbound local error: I had my answer from Bartleby: 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): d=histogram(s) for i in d.values(): if i!=1: return True return False def missing_letters(s): missing_letters_string="" d=histogram(s) for ch in alphabet: if ch not in d.keys(): missing_letters_strings+=ch return missing_letters_string for s in test_dups: if has_duplicates(s): print(s+"has duplicates") else: print(s+"has no duplicates") print("\n") for s in test_miss: missing_letters_string=missing_letters(s) if missing_letters_string!="": pring(s+" is missing letters "+missing_letters_string) else: print(s+" uses all the letters") print("\n")
Start with the following Python code.
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
Please help with Bartleby homework answered, I had received an error message for Unbound local error:
I had my answer from Bartleby:
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):
d=histogram(s)
for i in d.values():
if i!=1:
return True
return False
def missing_letters(s):
missing_letters_string=""
d=histogram(s)
for ch in alphabet:
if ch not in d.keys():
missing_letters_strings+=ch
return missing_letters_string
for s in test_dups:
if has_duplicates(s):
print(s+"has duplicates")
else:
print(s+"has no duplicates")
print("\n")
for s in test_miss:
missing_letters_string=missing_letters(s)
if missing_letters_string!="":
pring(s+" is missing letters "+missing_letters_string)
else:
print(s+" uses all the letters")
print("\n")
![2 IDLE Shell 3.9.5
File Edit Shell Debug Options Window Help
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64) ] on win32
Type "help", "copyright", "credits" or "license ()" for more information.
>>>
= RESTART: F:/CS Programming Fundamentals/Unit 7/Unit7LearningJournal Getfunction.py
zzzhas no duplicates
doghas no duplicates
bookkeeperhas no duplicates
subdermatoglyphichas no duplicates
subdermatoglyphicshas no duplicates
Traceback (most recent call last):
File "F:/CS Programming Fundamentals/Unit 7/Unit7LearningJournal Getfunction.py", line 38, in <module>
missing letters string=missing letters (s)
File "F:/CS Programming Fundamentals/Unit 7/Unit7LearningJournal Getfunction.py", line 27, in missing letters
missing_letters strings+=ch
UnboundLocalError: local variable 'missing letters strings' referenced before assignment
>>>
= RESTART: F:/CS Programming Fundamentals/Unit 7/Unit7LearningJournal Getfunction.py
zzzhas no duplicates
doghas no duplicates
bookkeeperhas no duplicates
subdermatoglyphichas no duplicates
subdermatoglyphicshas no duplicates
Traceback (most recent call last) :
File "F:/CS Programming Fundamentals/Unit 7/Unit7LearningJournal Getfunction.py", line 38, in <module>
missing letters string=missing letters (s)
File "F:/CS Programming Fundamentals/Unit 7/Unit7LearningJournal_Getfunction.py", line 27, in missing_letters
missing letters strings+=ch
UnboundLocalError: local variable 'missing letters strings' referenced before assignment
>>>
Ln: 2 Col: 1
10:13 PM
P Search for anything
A 4) O
W
99+
5/25/2021](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2b3e0ad1-27e4-45d5-9d4c-cf1a19e4c930%2Fb7dce8f3-2f42-4b08-aba3-f7b2de158f35%2F5tt6rsm_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images









