repl.it
@AhmadAyyeh/

soundex 2

Python

No description

fork
loading
Files
  • main.py
  • DMV.jpg
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'''
Zain Abbas + Ahmad Ayyeh
5/15/19
Drivers license program
the drivers license program is designed to generate a liscense plate number for the user based on a series of their inputs.
variable list:
soundex: a function that would generate the first four digits.
soundex_code: a list that would contain the 4-character code for surnames.
last_name: asks the user for last name.
ONES: letters that would generate the number 1.
TWOS: letters that would generate the number 2.
THREES: letters that would generate the number 3.
FIVES: letters that would generate the number 5.
IGNORED: letters that are ignored.
'''
def soundex():
  soundex_code = []
  last_name=input("\nWhat is your last name? ").upper()
  soundex_code.append(last_name[0])
  #this block of code will delete a doubled letter if there's double letters in the last name.
  ONES = ("B" , "P" , "F" , "V")
  TWOS = ("C" , "S" , "K" , "G" , "J" , "Q" , "X" , "Z")
  THREES = ('D' , 'T')
  FIVES = ('M' , 'N')
  IGNORED = ('A' , 'E' , 'I' , 'O' , 'U' , 'W' , 'Y' , 'H')
  last_name = list(last_name)
  if " " in last_name:
    last_name.remove(" ")
  for i in range (0, len(last_name) - 1):
    j = i + 1
    if last_name[j] == last_name[i]:
        del last_name[j]
        last_name.append(i)
    if last_name[i] in IGNORED:
      last_name.remove(last_name[i])
      last_name.append(i)
  #converting surname characters into a code.
  for x in range (1 , 4):
    if last_name[x] in ONES:
      if last_name [x+1] in ONES:
        del last_name[x + 1]
      soundex_code.append(1)
    elif last_name[x] in TWOS:
      if last_name[x + 1] in TWOS:
        del last_name [x + 1]
      soundex_code.append(2)
    elif last_name[x] in THREES:
      if last_name[x + 1] in THREES:
        del last_name[x + 1]
      soundex_code.append(3)
    elif last_name[x] == 'L':
      if last_name[x + 1] == 'L':
        del last_name[x + 1]
      soundex_code.append(4)
    elif last_name[x] in FIVES:
      if last_name[x + 1] in FIVES:
        del last_name[x + 1]
      soundex_code.append(5)
    elif last_name[x] == 'R':
      if last_name[x + 1] == 'R':
        del last_name[x + 1]
      soundex_code.append(6)
  if len(soundex_code) == 1:
    soundex_code.append(0) , soundex_code.append(0) , soundex_code.append(0)
  elif len(soundex_code) == 2:
    soundex_code.append (0) , soundex_code.append(0)
  elif len(soundex_code) ==3:
    soundex_code.append(0)  
  for i in soundex_code:
    print (i , end = '' )

soundex()