Python Forum
Park-Miller Algorithm
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Park-Miller Algorithm
#9
Thank you. My class "Mnemonic" is used to generate a name out of a given phone number. For example, if the input of phone number is 6862377, then some possible outputs are: 
print('"' + m.make('6862377') + '"')  #  "ounadrr"
print('"' + m.make('6862377') + '"')  #  "ounadrs"
print('"' + m.make('6862377') + '"')  #  "ntobers"
print('"' + m.make('6862377') + '"')  #  "ouncerr"
print('"' + m.make('6862377') + '"')  #  "ntoadrr"
print('"' + m.make('6862377') + '"')  #  "muncess"
print('"' + m.make('6862377') + '"')  #  "ounadrs"
print('"' + m.make('6862377') + '"')  #  "munadrs"
print('"' + m.make('6862377') + '"')  #  "ouncers"
print('"' + m.make('6862377') + '"')  #  "otoadrr"
I tried to make a few print statements in my code, and some print statements are not even showing in my terminal. I don't know why.
def make(self,number):
    self.num = number
    self.s1=''
    self.s3=''
    print("First number is", self.num[0])
    print("Letters associated with",self.num[0],"is",self.letters[int(self.num[0])][1])
    i = 0
    self.s1+=self.random.choose(self.letters[int(self.num[0])])
    print("String s1 is",self.s1)
    while i < len(self.num):
        # self.s4 +=self.random.choose(self.letters[int(self.num)])
        self.s2 = ''
        self.s2 += self.follow[self.s1]
        print("String s2 is", self.s2)
        print("Length of s2 is", len(self.s2))
        j = 0
        while j <= len(self.s2):
            found_char = False
            if self.s2[j]==self.letters[int(self.num[i+1])]:
                print("String next num is",self.letters[int(self.num[i+1])])

                self.s3+=self.s2[j]
                found_char = True
            j+=1
            print("String s3 is", self.s3)

        if found_char == False:
                return''
        i=+1

    self.s1 += self.random.choose(self.letters[self.s3])
    print("String s1 is now",self.s1)
    return self.s1
for instance, the last print statement does not show up in the terminal (I am using Intellij IDE now). I think my while loop with the counter j is messing up my code but I think my logic sounds reasonable. All I am trying to do is to check whether at each position in my string s2 contains a self.letters[int(self.num[i+1])][/python]. If it does, then I concatenate it to the new string s3. If none matches, I return an empty string. At then end, when I have a string s3 with all the matching letters in the string self.letters[int(self.num[i+1])], then I called the random.choose function again to pick a random letter out of that string and concatenate to string s1. Hmm I am having some thoughts about my while loop now, but I am working on them.
Reply


Messages In This Thread
Park-Miller Algorithm - by hughng92 - Feb-20-2017, 05:45 AM
RE: Park-Miller Algorithm - by micseydel - Feb-20-2017, 06:26 AM
RE: Park-Miller Algorithm - by hughng92 - Feb-20-2017, 06:37 AM
RE: Park-Miller Algorithm - by micseydel - Feb-20-2017, 06:45 AM
RE: Park-Miller Algorithm - by hughng92 - Feb-20-2017, 07:00 AM
RE: Park-Miller Algorithm - by buran - Feb-20-2017, 07:57 AM
RE: Park-Miller Algorithm - by hughng92 - Feb-20-2017, 05:37 PM
RE: Park-Miller Algorithm - by nilamo - Feb-20-2017, 05:48 PM
RE: Park-Miller Algorithm - by hughng92 - Feb-20-2017, 06:06 PM
RE: Park-Miller Algorithm - by merlem - Feb-20-2017, 07:57 PM
RE: Park-Miller Algorithm - by hughng92 - Feb-20-2017, 09:31 PM
RE: Park-Miller Algorithm - by nilamo - Feb-20-2017, 09:41 PM
RE: Park-Miller Algorithm - by hughng92 - Feb-20-2017, 10:12 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020