Conversation
| import random | ||
|
|
||
|
|
||
| def get_list_of_users_names() -> list: |
There was a problem hiding this comment.
May need more validations. User can enter an empty string or any punctuation as a name.
| while len(users_list_of_names) < 2: | ||
| users_input = input("Input more than one name, please: ").split(",") | ||
| users_list_of_names = [name.strip() for name in users_input] | ||
|
|
There was a problem hiding this comment.
May be better to turn into a set rather than a list at this point to remove any duplicate names entered by the user.
| The function takes the list of names and number and returns random names from this list | ||
| """ | ||
|
|
||
| print(random.choices(list_of_names, k=number)) |
There was a problem hiding this comment.
Prints a list rather than formatting it into a string. May look nicer for the user if the output is structured.
This can also return the same index / name more than once? print(random.sample(list_of_names, k=number)) picks unique indexes.
main.py
Outdated
|
|
||
| # check a wrong entered number | ||
| if user_number >= len(list_of_names): | ||
| print("Your number should be less than the number of names in the list! Try again.") |
There was a problem hiding this comment.
I think this goes over the pep8 character limit on a line? Could break after print( to a new line.
main.py
Outdated
| while True: | ||
|
|
||
| try: | ||
| user_number = int(input("Input the number of names, that you want to get: ")) |
There was a problem hiding this comment.
I think this goes over the pep8 character limit on a line? Could break after int( to a new line.
| import random | ||
|
|
||
|
|
||
| def get_list_of_users_names() -> list: |
There was a problem hiding this comment.
Function name could be more specific based on pep8 standards. i.e. including that it's a user input function.
| return users_list_of_names | ||
|
|
||
|
|
||
| def get_number_of_names(list_of_names: list) -> int: |
There was a problem hiding this comment.
Function name could be more specific based on pep8 standards. i.e. including that it's a user input function.
| return user_number | ||
|
|
||
|
|
||
| def get_random_names(list_of_names: list, number: int): |
There was a problem hiding this comment.
Function name could be more specific based on pep8 standards. i.e. select_random_names_from_list
No description provided.