Conversation
| print("Enter another name: ") | ||
| continue | ||
|
|
||
| print("Please only use letters: [a-zA-Z]. Try again.") |
There was a problem hiding this comment.
Would it not be cleaner to put the logic for the case where the user enters a non-alphabetic name in the else statement? That way, you could drop the two continue statements.
| names = [] | ||
|
|
||
|
|
||
| def add_name(): |
There was a problem hiding this comment.
Hey Adam, I echo Tom's comments here. Make sure you add documentation to your functions (function description, parameters, returns) and code.
| print( | ||
| "The amount of names you want to pick is larger than the number names you've inputted. Please try again") | ||
| continue | ||
| print("Please only use numbers. Try again.") |
There was a problem hiding this comment.
Nesting this in an else clause would mean you could drop the continue statements.
| # Check if the amount desired to pick is not more than the amount of names in the list | ||
| elif int(num_to_select) <= len(names): | ||
| chosen_names = random.choices(names, k=int(num_to_select)) | ||
| return print("Chosen names: ", chosen_names) |
There was a problem hiding this comment.
Why are you returning a print function?
| print("Please only use letters: [a-zA-Z]. Try again.") | ||
|
|
||
|
|
||
| def rand_name_amount(): |
|
|
||
|
|
||
| def add_name(): | ||
| print('Press x stop entering a name') |
There was a problem hiding this comment.
Use consistent quotation marks: sometimes you use single quotes '', and other times you use double "".
| I would also recommend using Visual Studio Code as your editor, but this is personal preference. Make sure you implement coding standards and Pythonic style in the application! | ||
| ## Instructions | ||
| 1) Enter a name of your desire and click enter. | ||
| 2) Click 'x' to pick the number of names you want to select. |
There was a problem hiding this comment.
Click 'x' to pick the number of names you want to select. This sounds like you are talking about closing the window.
|
A solid bit of code with some minor inconsistencies and room for improvement regarding readability. |
| * Check that only letters have been entered. | ||
| * Check that only numbers have been added. | ||
| * Check that the amount desired to pick is not more than the amount of names in the list. | ||
|
|
There was a problem hiding this comment.
Can you add Pseudocode here? Or a flow diagram of how the solution will look?
|
|
||
|
|
||
| def add_name(): | ||
| print('Press x stop entering a name') |
There was a problem hiding this comment.
Can you add more comments and documentation explaining what the function purpose is? Things to consider:
- Function description
- Parameters: data type, parameter description
- Returns: data type, what is returned from the function?
|
|
||
| def add_name(): | ||
| print('Press x stop entering a name') | ||
| print('Enter a name:') |
There was a problem hiding this comment.
You can just use input directly instead of printing and then calling input().
|
|
||
| if name == 'x': | ||
| # Check at least two names have been entered | ||
| if len(names) < 2: |
There was a problem hiding this comment.
Think about o the logic here. Thnk about this:
if len(names) >= 2:
break
else:
print('Please enter at least at least two names")
This makes more sense to me. What do you think?
There was a problem hiding this comment.
You can even use an AND here as well so that there isn't an if nested in an if.
| elif name.isalpha(): | ||
| names.append(name) | ||
| print("Enter another name: ") | ||
| continue |
There was a problem hiding this comment.
Can you structure this in a different way so that you don't need to use continue at the end of each condition.
No description provided.