Skip to content

Andrew's Random Name Generator#20

Open
BirchAD wants to merge 14 commits intoalexnaylor99:mainfrom
BirchAD:main
Open

Andrew's Random Name Generator#20
BirchAD wants to merge 14 commits intoalexnaylor99:mainfrom
BirchAD:main

Conversation

@BirchAD
Copy link

@BirchAD BirchAD commented Apr 11, 2023

No description provided.

main.py Outdated
import re

def get_user_inputs():
"""Ask user for inputs."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add more detailed docstrings, what the function actually does, checks, returns etc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I'd add annotations above, like def get_user_inputs() -> list, for example

# Check if the input list is empty
if not name_list:
return False
return True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can write just
: return name_list - more concisely, one line instead of 3

main.py Outdated
def remove_whitespace_after_commas(name_list):
"""Remove whitespace after commas in the name list."""
# Replace any whitespace that comes after a comma with just a comma
return re.sub(r',\s*', ',', name_list)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you can use the strip() method

# Check for and remove any empty strings in the input list
name_list = check_for_empty_string(name_list)
break
return name_list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or you can put 'return' inside while loop

main.py Outdated
"""Get a user input for the number that is an integer and lower than the number of names in the list submitted."""
while True:
# Ask the user to input a number lower than the number of names in the list
num_of_names = input(f"Enter a number {len(name_list)} or lower to randomly select that number of names from the list: ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not len(name_list) - 1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The length is the number of names in the list. -1 would be wrong?

# Create empty set to add random names to
selected_names = set()
# While the length of selected names is less than the number of names, add a randomly chosen name from the list
while len(selected_names) < num_of_names:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can use k parameter (An integer defining the length of the returned list), without using while loop and set

Copy link
Author

@BirchAD BirchAD Apr 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit cumbersome but I did this to make sure no duplicates names could be returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants