Skip to content

Osman Abdulrazak - Random Name Selector Project#29

Open
oar04 wants to merge 2 commits intoalexnaylor99:mainfrom
oar04:main
Open

Osman Abdulrazak - Random Name Selector Project#29
oar04 wants to merge 2 commits intoalexnaylor99:mainfrom
oar04:main

Conversation

@oar04
Copy link

@oar04 oar04 commented Apr 25, 2023

No description provided.

Comment on lines +16 to +26

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')
Copy link

@FurqanA1 FurqanA1 Apr 25, 2023

Choose a reason for hiding this comment

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

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.

Comment on lines +35 to +41
"""
Function takes an input and validates that its not empty

returns
-----
name_input : string
"""

Choose a reason for hiding this comment

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

I believe the code could look more neater without the comments for the functions formatted in this way

Copy link

@FurqanA1 FurqanA1 left a comment

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Could include strip function to remove commas and spaces so that they are formatted the same when printed out.

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