Skip to content

Completed Project#7

Open
Jhxnxvi wants to merge 4 commits intoalexnaylor99:mainfrom
Jhxnxvi:main
Open

Completed Project#7
Jhxnxvi wants to merge 4 commits intoalexnaylor99:mainfrom
Jhxnxvi:main

Conversation

@Jhxnxvi
Copy link

@Jhxnxvi Jhxnxvi commented Feb 16, 2023

No description provided.

Copy link

@vhuni vhuni left a comment

Choose a reason for hiding this comment

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

  • Functions are efficient with only a few lines of code used
  • No unnecessary loops
  • Overall code is simple and easy to understand. I have just a little question on one function but the rest looks good!

Comment on lines +12 to +17
while True:
num_names_str = input("Enter the number of names to be selected: ")
if num_names_str.isdigit():
return int(num_names_str)
else:
print("Invalid input. Please Enter a postive interger.")
Copy link

@vhuni vhuni Feb 17, 2023

Choose a reason for hiding this comment

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

  • Good short and concise function! Very easy to understand the whole function.
  • Does the function stop getting inputs if 'else' condition is triggered?
  • Does the 'if' condition consider negative values?

Copy link
Author

@Jhxnxvi Jhxnxvi Feb 17, 2023

Choose a reason for hiding this comment

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

Thank you for the comments!! In regards, to your question about the 'else' function, it will just tell you to "Enter the number of names to be selected:" again. The 'if' function does consider negative values when ran since the code only asks for positive integers and will pop up a message.

def get_shortlist():
# Reads the names that th user inputs and returns a list.
shortlist_str = input("Please enter names, separated by commas: ")
return [name.strip() for name in shortlist_str.split(',')]
Copy link
Owner

Choose a reason for hiding this comment

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

Really like the concise code here - top work!

return [name.strip() for name in shortlist_str.split(',')]

def get_num_names():
# Reads the number of names to be selected from the list and returns the interger.
Copy link
Owner

Choose a reason for hiding this comment

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

Could you add more comprehensive docstrings?

Copy link
Owner

Choose a reason for hiding this comment

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

i.e. function descriptions, parameters (in this case none!) and what is returned


def select_names(shortlist, num_names):
# Selects num_names names randomly from the given list and returns a list.
return random.sample(shortlist, num_names)
Copy link
Owner

Choose a reason for hiding this comment

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

Good use of the random library!

num_names = get_num_names()

if num_names > len(shortlist):
print(f" Please enter the number of names to be selected: ({num_names}) is greater than the number of names in the shortlist ({len(shortlist)}.")
Copy link
Owner

Choose a reason for hiding this comment

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

Could you put this into a loop? Currently, the user will have to restart the script - just something to think about going forward.

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.

3 participants