@AhmadAyyeh/

soundex 2

Python

No description

fork
loading
Files
  • main.py
  • DMV.jpg

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5084552064850374","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"JycnClphaW4gQWJiYXMgKyBBaG1hZCBBeXllaAo1LzE1LzE5CkRyaXZlcnMgbGljZW5zZSBwcm9ncmFtCnRoZSBkcml2ZXJzIGxpY2Vuc2UgcHJvZ3JhbSBpcyBkZXNpZ25lZCB0byBnZW5lcmF0ZSBhIGxpc2NlbnNlIHBsYXRlIG51bWJlciBmb3IgdGhlIHVzZXIgYmFzZWQgb24gYSBzZXJpZXMgb2YgdGhlaXIgaW5wdXRzLgp2YXJpYWJsZSBsaXN0Ogpzb3VuZGV4OiBhIGZ1bmN0aW9uIHRoYXQgd291bGQgZ2VuZXJhdGUgdGhlIGZpcnN0IGZvdXIgZGlnaXRzLgpzb3VuZGV4X2NvZGU6IGEgbGlzdCB0aGF0IHdvdWxkIGNvbnRhaW4gdGhlIDQtY2hhcmFjdGVyIGNvZGUgZm9yIHN1cm5hbWVzLgpsYXN0X25hbWU6IGFza3MgdGhlIHVzZXIgZm9yIGxhc3QgbmFtZS4KT05FUzogbGV0dGVycyB0aGF0IHdvdWxkIGdlbmVyYXRlIHRoZSBudW1iZXIgMS4KVFdPUzogbGV0dGVycyB0aGF0IHdvdWxkIGdlbmVyYXRlIHRoZSBudW1iZXIgMi4KVEhSRUVTOiBsZXR0ZXJzIHRoYXQgd291bGQgZ2VuZXJhdGUgdGhlIG51bWJlciAzLgpGSVZFUzogbGV0dGVycyB0aGF0IHdvdWxkIGdlbmVyYXRlIHRoZSBudW1iZXIgNS4KSUdOT1JFRDogbGV0dGVycyB0aGF0IGFyZSBpZ25vcmVkLgonJycKZGVmIHNvdW5kZXgoKToKICBzb3VuZGV4X2NvZGUgPSBbXQogIGxhc3RfbmFtZT1pbnB1dCgiXG5XaGF0IGlzIHlvdXIgbGFzdCBu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HBlbmQoMCkKICBlbGlmIGxlbihzb3VuZGV4X2NvZGUpID09MzoKICAgIHNvdW5kZXhfY29kZS5hcHBlbmQoMCkgIAogIGZvciBpIGluIHNvdW5kZXhfY29kZToKICAgIHByaW50IChpICwgZW5kID0gJycgKQoKc291bmRleCgp"},"asBuffer":null},"loaded":true}}
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()