Question

Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is...

Write a structured (procedural) Python program that solves the following spec:

Soundex System Coding: Soundex is a system that encodes a word into a letter followed by three numbers that roughly describe how the word sounds. Therefore, similar sounding words have the same four-character code. Use the following set of (slightly modified #4) rules to create a translator from English words to Soundex Code:

  1. Retain the first letter of the word.
  2. For letters 2 …n, delete any/all occurrences of the vowels (a,e,I,o,u), h, w, y.
  3. Assign the following numbers to any remaining letters in the word
    1. 1 for occurrences of b, f, p, v.
    2. 2 for occurrences of c, g, j, k, q, s, x, z
    3. 3 for occurrences of d, t
    4. 4 for L
    5. 5 for M, N
    6. 6 for R
  4. For repeated numbers, remove the repeats (“PROGRAMMING” à P6265552 à P62652)
  5. Keep only the first four characters of what you have left (P62652 à P626) However, if you have less than 4 characters, 0 fill the empty spots so that ALL words have 4-character soundex codes. (e.g. “Anita” à A53 à A530)

Python program Requirements: Your program is expected to…

  1. Well-documented (name, date, description at the top; good naming conventions)
  2. provide a description and instructions for the user.
  3. ask for the player’s name and encode it for them, then use their Soundex code name to refer to them.
  4. Ask them to encode as many names/words as they would like to until they enter 0 to quit.
  5. have a minimum of 4 subprograms (including a main() ).
  6. store the entered names/words with their codes into a dictionary (name/word as key). When they are finished, present them with a sorted list of the name/words and their soundex codes neatly formatted.

Soundex is primarily used as a tool to group homophobic English-sounding surnames. It was developed by Robert C. Russell and Margaret King over 100 years ago!

You can read more about it at Wikipedia: https://en.wikipedia.org/wiki/Soundex

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the python code with screenshot. I ran for two words PRORAMMING and ANITA and its giving the right soundex code.

let me know for any questions, comments added for each important function

=======================================================================

# function accepts a raw word
# function returns a word with deleted vowel and letters HWY

def delete_vowels(word):
    word = word.upper()
    delete_letters = ['A', 'E', 'I', 'O', 'U', 'H', 'W', 'Y']
    modified = word[0]
    for letter in word[1:]:
        if letter not in delete_letters:
            modified += letter
    return modified


# function takes a word (with deleted vowels) and return the final soundex code
def assign_number(word):
    # letter to number dictionary
   
letter_keys = {'B': 1, 'F': 1, 'P': 1, 'V': 1, 'C': 2, 'G': 2, 'J': 2, 'K': 2, 'Q': 2, 'S': 2, 'X': 2, 'Z': 2,
                   'D': 3, 'T': 3, 'L': 4, 'M': 5, 'N': 5, 'R': 6}

    previous = 0 # track the previous letter
   
modified = word[0] # keep the first letter
    # iterate over each letter in the word
   
for i in range(1, len(word)):
        if i == 1:
            previous = letter_keys.get(word[i])
            modified += str(letter_keys.get(word[i]))
        else:
            number = letter_keys.get(word[i])
            if number != previous:
                modified += str(number)
                previous = number
    if len(modified) >= 4:
        return modified[:4]
    else: # append extra 0 at the end
       
spaces = 4 - len(modified)
        return modified + '0' * spaces


# main function that accepts a raw word and retursn the soundex code of the word
def convert_to_soundex(word):
    word = delete_vowels(word)
    return assign_number(word)


def main():
    # keeping asking user for a word or name until user enters 0
   
while True:
        word = input('Enter a word/name to convert (enter 0 to quit): ').upper()
      if word == '0': break
       
print(convert_to_soundex(word))


main()

1: Project untitled - [C:\Users\248341\Pycharm Projects\untitled] - ... \Name.py - PyCharm Community Edition 4.0.3 File Edit

Add a comment
Know the answer?
Add Answer to:
Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • python Hi I have a project due on this Friday and I really can’t seem to figure this code out. If anyone could writ...

    python Hi I have a project due on this Friday and I really can’t seem to figure this code out. If anyone could write this for me it’d be very appreciated. Thank you! The Soundex Code code for surnames. It was code. All Al Soundex is a system that designed to produce one code for natha may be speled differenty, similar sounds. For example, Horn and Heron the same Soundex US Census Indexes from 1880 to the most recent availabie...

  • python Hi I have a project due on this Friday and I really can’t seem to figure this code out. If anyone could writ...

    python Hi I have a project due on this Friday and I really can’t seem to figure this code out. If anyone could write this for me it’d be very appreciated. Thank you! The Soundex Code code for surnames. It was code. All Al Soundex is a system that designed to produce one code for natha may be speled differenty, similar sounds. For example, Horn and Heron the same Soundex US Census Indexes from 1880 to the most recent availabie...

  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • I need help with building the program since Huffman's algorithm is not clear. I would appreciate...

    I need help with building the program since Huffman's algorithm is not clear. I would appreciate if a pseudo code for encoding and decoding the algorithm is provided, as well as the program for both of them since it deals with English text instead of characters. I'd appreciate it if it was in C++, or Java. 1. si o Write a program that constructs a Huffman code for a given English text and encode it. The English character occurrence probabilities...

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

  • Create a python code named LetterCount with a text file named words.txt that contains at least...

    Create a python code named LetterCount with a text file named words.txt that contains at least 100 words in any format - some words on the same line, some alone (this program involves no writing so you should not be erasing this file). Then create a program in the main.py that prompts the user for a file name then iterates through all the letters in words.txt, counting the frequency of each letter, and then printing those numbers at the end...

  • Make a C program to count the number of occurrences of words from the input. For...

    Make a C program to count the number of occurrences of words from the input. For example, with input "one two one three one two" your program should output: one 3 two 2 three 1 It should work for up to 100 different words. If there are more than 100 unique words in the input, the program should still work, and count the number of appearances of the first 100 unique words. Each word should have the same maximum amount...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • please use c++ please write down the input file information please add comments for some codes...

    please use c++ please write down the input file information please add comments for some codes please do not use #include <bits/stdc++.h> we did not learn it yet thank you CSIT 575-Take Home Lab #11: Arrays To learn to code, compile and run a program processing characters. Assignment Plan and code a top-down modular program utilizing ARRAYS to solve the following problem, using at least 3 functions (called from the main() section or from another function) to solve the problem....

  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT