Skip to content

Hinesh Tailor, Random Name Generator Submission#28

Open
HineshX wants to merge 5 commits intoalexnaylor99:mainfrom
HineshX:main
Open

Hinesh Tailor, Random Name Generator Submission#28
HineshX wants to merge 5 commits intoalexnaylor99:mainfrom
HineshX:main

Conversation

@HineshX
Copy link

@HineshX HineshX commented Apr 25, 2023

No description provided.

print("Here are your names:")
for name in selected_names:
print(name)
return random_name_generator()

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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:

Choose a reason for hiding this comment

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

If the user enters 0, then the programme returns an empty list.

Choose a reason for hiding this comment

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

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:

Choose a reason for hiding this comment

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

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]

Choose a reason for hiding this comment

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

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!')

Choose a reason for hiding this comment

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

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()

Choose a reason for hiding this comment

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

Here you would write:

if __name__ == '__main__':
____ random_name_generator()

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.

2 participants