Skip to content

completed project#13

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

completed project#13
Scharukh7 wants to merge 2 commits intoalexnaylor99:mainfrom
Scharukh7:main

Conversation

@Scharukh7
Copy link

No description provided.

@@ -0,0 +1,43 @@
import random

# Function to randomly select a specified number of names from a list of names

Choose a reason for hiding this comment

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

Good use of comments: The code contains useful comments that explain what each part of the code does. This makes it easier for others to understand and maintain the code.

import random

# Function to randomly select a specified number of names from a list of names
def random_name_selector(names, num_selections):

Choose a reason for hiding this comment

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

Good use of functions: The code defines a function random_name_selector to perform the core task of randomly selecting names. This is good programming practice as it makes the code more modular and reusable.

Choose a reason for hiding this comment

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

The code uses consistent style throughout, including indentation, spacing, and variable naming. This makes the code easy to read and understand.

@MarioTawfelis
Copy link

Great use of try/catch to handle errors.

One thing to consider and it's more so about the concept rather than coding practice, you wouldn't want to return the full list back to the user as the purpose is to narrow down the provided list by returning a randomly selected subset of the provided list. To do this, it could be as simple as changing your condition to

if num_selections > 0 and num_selections < len(names):

instead of

if num_selections > 0 and num_selections <= len(names):

Note the operator for the second condition.

return selected_names
else:
# Return an error message if the number of selections is invalid
return "Invalid input: number of selections should be between 1 and the length of the shortlist."

Choose a reason for hiding this comment

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

Use f-strings for error message: The code currently returns an error message as a string. It would be more Pythonic to use f-strings to format the error message, like so: return f"Invalid input: number of selections should be between 1 and {len(names)}.".

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