Hinesh Tailor, Random Name Generator Submission#28
Hinesh Tailor, Random Name Generator Submission#28HineshX wants to merge 5 commits intoalexnaylor99:mainfrom
Conversation
| print("Here are your names:") | ||
| for name in selected_names: | ||
| print(name) | ||
| return random_name_generator() |
There was a problem hiding this comment.
This is an infinite loop, there is no way to break out or end the programme. You might include a break clause like:
if list_of_names == 'quit':
____ quit()
This would allow the user to end the loop.
| @@ -0,0 +1,26 @@ | |||
| import random | |||
There was a problem hiding this comment.
Usually you add a docstring at the beginning of the script to summarise the code.
| # Prompts user to input number of names he would like | ||
| while True: | ||
| num_of_names = input("Enter the number of names you would like:") | ||
| if not num_of_names.isdigit() or len(list_of_names) < int(num_of_names) or int(num_of_names) <= 0: |
There was a problem hiding this comment.
If the user enters 0, then the programme returns an empty list.
There was a problem hiding this comment.
You also might try adding a try-except block to check if it is a number!
| list_of_names = [i.strip(" ") for i in list_of_names] | ||
|
|
||
| # Prompts user to input number of names he would like | ||
| while True: |
There was a problem hiding this comment.
This might need a docstring to explain the inputs, outputs and a summary of the function.
| # Prompts user to input names and creates a list | ||
| list_of_names = input("Enter a list of names seperated by commas:") | ||
| list_of_names = list_of_names.split(",") | ||
| list_of_names = [i.strip(" ") for i in list_of_names] |
There was a problem hiding this comment.
If the user enters an empty string, the programme won't allow them to pick a number. You might add some validation:
if list_of_names = '':
____ print('Can't do it!')
There was a problem hiding this comment.
If I accidentally add a comma at the end of the string, it will create an extra item in the list. You might look at the pop() method here.
| print(name) | ||
| return random_name_generator() | ||
|
|
||
| random_name_generator() |
There was a problem hiding this comment.
Here you would write:
if __name__ == '__main__':
____ random_name_generator()
No description provided.