Some general comments:
The Python style guide recommends that lines should be wrapped to 79 characters; comments or docstrings to 72. A lot of your comments disappear of the side of the screen in my editor. Try to make your lines shorter.
Most Python variable names are
lowercase_with_underscoresnake_case
, notdromedaryCasecamelCase
, with the exception of class names, which areCamelCasePascalCase
.Your variable names are pretty obtuse. Using
ten
orhundred
for random integers makes the program much harder to read, because the name sounds like these are constants, not random values.Your comments need some work. For example:
attempts = attempts + 1 #Adds one to the number of attempts the user has taken to guess the number.
This is pretty much the anti-pattern for comments. Comments should explain why the code works this way, not repeat information that I could learn by reading the code.
Most of your comments are redundant or unnecessary, and can be removed. In particular, don’t explain why you’re importing modules unless it’s particularly unusual – this just adds visual noise, and is prone to become out-of-date.
Your three functions
oneToTen()
,oneToTwenty()
andoneToFifty()
are all very similary. It would be better to have a singleguess_number(max_number)
function which asks the user to guess a number between 1 and max_number, and just call this with different parameters as appropriate, than to have all the code copying.Using
sys.exit()
is a terrible way to yield control flow from a function, because it kills the entire script. It’s much better to usereturn
, in case the rest of the program needs to continue.If I give your program totally invalid input, it says nothing and just exits silently. It should warn me if I’ve used an inappropriate choice.
Some general comments:
The Python style guide recommends that lines should be wrapped to 79 characters; comments or docstrings to 72. A lot of your comments disappear of the side of the screen in my editor. Try to make your lines shorter.
Most Python variable names are
lowercase_with_underscore
, notdromedaryCase
, with the exception of class names, which areCamelCase
.Your variable names are pretty obtuse. Using
ten
orhundred
for random integers makes the program much harder to read, because the name sounds like these are constants, not random values.Your comments need some work. For example:
attempts = attempts + 1 #Adds one to the number of attempts the user has taken to guess the number.
This is pretty much the anti-pattern for comments. Comments should explain why the code works this way, not repeat information that I could learn by reading the code.
Most of your comments are redundant or unnecessary, and can be removed. In particular, don’t explain why you’re importing modules unless it’s particularly unusual – this just adds visual noise, and is prone to become out-of-date.
Your three functions
oneToTen()
,oneToTwenty()
andoneToFifty()
are all very similary. It would be better to have a singleguess_number(max_number)
function which asks the user to guess a number between 1 and max_number, and just call this with different parameters as appropriate, than to have all the code copying.Using
sys.exit()
is a terrible way to yield control flow from a function, because it kills the entire script. It’s much better to usereturn
, in case the rest of the program needs to continue.If I give your program totally invalid input, it says nothing and just exits silently. It should warn me if I’ve used an inappropriate choice.
Some general comments:
The Python style guide recommends that lines should be wrapped to 79 characters; comments or docstrings to 72. A lot of your comments disappear of the side of the screen in my editor. Try to make your lines shorter.
Most Python variable names are
snake_case
, notcamelCase
, with the exception of class names, which arePascalCase
.Your variable names are pretty obtuse. Using
ten
orhundred
for random integers makes the program much harder to read, because the name sounds like these are constants, not random values.Your comments need some work. For example:
attempts = attempts + 1 #Adds one to the number of attempts the user has taken to guess the number.
This is pretty much the anti-pattern for comments. Comments should explain why the code works this way, not repeat information that I could learn by reading the code.
Most of your comments are redundant or unnecessary, and can be removed. In particular, don’t explain why you’re importing modules unless it’s particularly unusual – this just adds visual noise, and is prone to become out-of-date.
Your three functions
oneToTen()
,oneToTwenty()
andoneToFifty()
are all very similary. It would be better to have a singleguess_number(max_number)
function which asks the user to guess a number between 1 and max_number, and just call this with different parameters as appropriate, than to have all the code copying.Using
sys.exit()
is a terrible way to yield control flow from a function, because it kills the entire script. It’s much better to usereturn
, in case the rest of the program needs to continue.If I give your program totally invalid input, it says nothing and just exits silently. It should warn me if I’ve used an inappropriate choice.
Some general comments:
The Python style guide recommends that lines should be wrapped to 79 characters; comments or docstrings to 72. A lot of your comments disappear of the side of the screen in my editor. Try to make your lines shorter.
Most Python variable names are
lowercase_with_underscore
, notdromedaryCase
, with the exception of class names, which areCamelCase
.Your variable names are pretty obtuse. Using
ten
orhundred
for random integers makes the program much harder to read, because the name sounds like these are constants, not random values.Your comments need some work. For example:
attempts = attempts + 1 #Adds one to the number of attempts the user has taken to guess the number.
This is pretty much the anti-pattern for comments. Comments should explain why the code works this way, not repeat information that I could learn by reading the code.
Most of your comments are redundant or unnecessary, and can be removed. In particular, don’t explain why you’re importing modules unless it’s particularly unusual – this just adds visual noise, and is prone to become out-of-date.
Your three functions
oneToTen()
,oneToTwenty()
andoneToFifty()
are all very similary. It would be better to have a singleguess_number(max_number)
function which asks the user to guess a number between 1 and max_number, and just call this with different parameters as appropriate, than to have all the code copying.Using
sys.exit()
is a terrible way to yield control flow from a function, because it kills the entire script. It’s much better to usereturn
, in case the rest of the program needs to continue.If I give your program totally invalid input, it says nothing and just exits silently. It should warn me if I’ve used an inappropriate choice.