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")

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education