Conversation
…1 name is submitted by separating the get user input within the select random names function
main.py
Outdated
| import re | ||
|
|
||
| def get_user_inputs(): | ||
| """Ask user for inputs.""" |
There was a problem hiding this comment.
I'd add more detailed docstrings, what the function actually does, checks, returns etc
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: ") |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Or you can use k parameter (An integer defining the length of the returned list), without using while loop and set
There was a problem hiding this comment.
It's a bit cumbersome but I did this to make sure no duplicates names could be returned.
No description provided.