Skip to content

Completed project#9

Open
adstads1 wants to merge 8 commits intoalexnaylor99:mainfrom
adstads1:main
Open

Completed project#9
adstads1 wants to merge 8 commits intoalexnaylor99:mainfrom
adstads1:main

Conversation

@adstads1
Copy link

No description provided.

print("Enter another name: ")
continue

print("Please only use letters: [a-zA-Z]. Try again.")
Copy link

Choose a reason for hiding this comment

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

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():
Copy link

Choose a reason for hiding this comment

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

Add a docstring.

Copy link
Owner

Choose a reason for hiding this comment

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

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.")
Copy link

Choose a reason for hiding this comment

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

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)
Copy link

Choose a reason for hiding this comment

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

Why are you returning a print function?

print("Please only use letters: [a-zA-Z]. Try again.")


def rand_name_amount():
Copy link

Choose a reason for hiding this comment

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

Add docstring.



def add_name():
print('Press x stop entering a name')
Copy link

Choose a reason for hiding this comment

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

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.
Copy link

Choose a reason for hiding this comment

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

Click 'x' to pick the number of names you want to select. This sounds like you are talking about closing the window.

@tjkuson
Copy link

tjkuson commented Feb 17, 2023

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.

Copy link
Owner

Choose a reason for hiding this comment

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

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')
Copy link
Owner

Choose a reason for hiding this comment

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

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:')
Copy link
Owner

Choose a reason for hiding this comment

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

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:
Copy link
Owner

Choose a reason for hiding this comment

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

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?

Copy link
Owner

Choose a reason for hiding this comment

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

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
Copy link
Owner

@alexnaylor99 alexnaylor99 Mar 16, 2023

Choose a reason for hiding this comment

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

Can you structure this in a different way so that you don't need to use continue at the end of each condition.

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