Skip to content

Commit

Permalink
Fixed 0 in request.txt crash, type subscript crash, and bug where fin…
Browse files Browse the repository at this point in the history
…al name was not returned
  • Loading branch information
ansengarvin committed Feb 20, 2022
1 parent 93aa161 commit 7dabe0f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1,010 deletions.
15 changes: 7 additions & 8 deletions getnames.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,16 @@ def get_name_list(num_words, consonants, single_vowels, double_vowels):

if generation_attempt_tracker == 1000:
print("ERROR: Too many words requested. Please choose a smaller number.")
return get_error_list(num_words, "ERROR: Too many words requested. Please choose a smaller number.")
return ["ERROR: Too many words requested. Please choose a smaller number."]

return name_list


def get_error_list(n, message):
def get_error_list(message):
"""
Populates an array with a given message n times.
"""
error_array = []
for i in range[n]:
error_array.append(message)

error_array = [message]
return error_array


Expand All @@ -104,11 +101,11 @@ def get_error_list(n, message):

if len(lines) > 0:
print("Received Request")
if lines[0].isnumeric():
if lines[0].isnumeric() and int(lines[0]) > 1:
name_list = get_name_list(int(lines[0]), consonants, single_vowels, double_vowels)
else:
print("ERROR: Non-number requested.")
name_list = get_error_list(20, "ERROR: Non-Number Requested")
name_list = ["ERROR: Invalid Requested"]

f = open('request.txt', 'w')
f.write("")
Expand All @@ -121,6 +118,8 @@ def get_error_list(n, message):
contents += name_list[i]
if i != len(name_list) - 1:
contents += '\n'

contents += name_list[len(name_list) - 1]
f.write(contents)
f.close()

3 changes: 0 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ close response.txt


TROUBLESHOOTING
Problem: Program crashes with "Type object is not superscriptable"
Solution: This usually happens when something's wrong with whatever's input into request.txt. You may be able to fix this by completely clearing the contents of requests.txt

Problem: response.txt is populated with "ERROR: Too many words requested. Please choose a smaller number."
Solution: This program tries to generate entirely unique names, so this happens when the program runs out of possible words to generate. You are generally a able to generate up over 10,000 names, but if you get this message, input a smaller number.

Expand Down
Loading

0 comments on commit 7dabe0f

Please sign in to comment.