Osman Abdulrazak - Random Name Selector Project#29
Osman Abdulrazak - Random Name Selector Project#29oar04 wants to merge 2 commits intoalexnaylor99:mainfrom
Conversation
|
|
||
| while True: | ||
| shortlist_count = input('Enter the number of names you want selected: ') | ||
| if shortlist_count.isdigit() and int(shortlist_count) > 0: | ||
| shortlist_count = int(shortlist_count) | ||
| if shortlist_count <= len(name_list): | ||
| break | ||
| else: | ||
| print(f'You entered {shortlist_count}, but there are only {len(name_list)} names in the list. Please enter a smaller number.') | ||
| else: | ||
| print(f'You entered {shortlist_count}, but you must select a valid number of 1 or higher') |
There was a problem hiding this comment.
Could do with using a try and except to possibly make the code a bit more concise. This could avoid having if and else statements within an if and else statement.
| """ | ||
| Function takes an input and validates that its not empty | ||
|
|
||
| returns | ||
| ----- | ||
| name_input : string | ||
| """ |
There was a problem hiding this comment.
I believe the code could look more neater without the comments for the functions formatted in this way
There was a problem hiding this comment.
The code has good structure overall. Good use of functions to separate out the name generator and validation. I would add comments at most stages to explain what each group of lines specifically do and what they check for. This would make it more easily understandable to the reader. The code works well, and includes some checks of validation. One check that could be added is to ensure that no integers can be inputted when requesting names.
| name_input = input('Enter a list of names separated by a comma: ') | ||
| while len(name_input) == 0 or name_input.isspace(): | ||
| name_input = input('Enter a valid name or names please: ') | ||
| return name_input |
There was a problem hiding this comment.
Could include strip function to remove commas and spaces so that they are formatted the same when printed out.
No description provided.