Henry Opara - Python Project#22
Henry Opara - Python Project#22HenryXanderTalent wants to merge 10 commits intoalexnaylor99:mainfrom
Conversation
ctorrington
left a comment
There was a problem hiding this comment.
Reviews left! Really enjoyed the solution. :)
| #Retrieve initial input | ||
| '''The code below will add the initial name to the list''' | ||
| name_input = input("Enter a name to add to your shortlist or press enter to continue: ") | ||
|
|
||
| if name_input != '': | ||
|
|
||
| validateName(name_input) | ||
|
|
||
| else: | ||
|
|
||
| validateEntKey(name_input) |
There was a problem hiding this comment.
Nice to see the programme starting at the bottom of the file, I would recommend starting execution from inside a more standard structure such as below though. Here specifically, it would require setting the correct module name.
if '__name__' == '__main__': main()
There was a problem hiding this comment.
I'm not sure about the newlines after every statement. It does make the code harder to read, especially with the multiple nested conditional statements, sometimes it is not possible to see where a statement has been nested.
There was a problem hiding this comment.
The PEP8 standard for function names is snake_case.
| #return output | ||
|
|
||
| #Add names to the list | ||
| def enterName(): |
There was a problem hiding this comment.
This is the same logic as the code at the bottom of the file, there is no need to repeat the code.
This function could be called as entry into the programme.
|
|
||
| print('Names entered must contain letters only') | ||
|
|
||
| name_input = None |
There was a problem hiding this comment.
You're not using the global variable for the name_input variable & so setting it to None here will only change it in the function scope, there is no need to do this since the function does not use the name_input variable again.
| #Validate the number entered | ||
| def validateNum(num_input): | ||
| '''This function will validate the number entered is a number otherwise request a new entry''' | ||
| if num_input.isdigit() is not True: |
There was a problem hiding this comment.
isdigit() will return True if there are digits & False otherwise, there is no need to check if it is not True.
You could say, if not num_input.isdigit():.
|
|
||
| addNum() | ||
|
|
||
| if num_input.isnumeric() is not True: |
There was a problem hiding this comment.
I'm not sure what the difference is between isdigit() & isnumeric() & if both are necessary.
Please use option 2