*#Your code is very readable...more so than some experienced people ;^)*
Thank you, that is very motivating that I am at least on the right track!
#A few suggestions (and assuming Python 3.X, since that's what it looks
like):
Yeah it is 3.1, forgot to mention that.
# * list shadows a built-in type, and should not be used for variable
names. names would be more appropriate.
I used list as it was a list and therefore new what argument to pass. I did
not even consider that this would be confusing! Thank you for pointing it
out.
# * input() return a string, so no need for str(input(...)).
# * range(x) is equivalent to range(0,x).
Thank you, I will note these for future code :)
#* The two loops in InitiateEntries can be consolidated:
Thank you, Seems a much better way or doing it.
#* Prefer for name in names: instead of using indexing, or for idx,name
in enumerate(names): if indexes are needed. Example:
# * Since 1-based indexing was used elsewhere to present names to the user,
the PrintEntries display code should also use idx+1
I thought that by using an index would be an easy way for the user to select
which element of the list to edit. Not seem the enumerate keyword before so
I will look up what that does :)
.
# * When returning a boolean value, you can simpify:
Ah, thank you!
Really useful feedback, I will note the points highlighted for my next
mini-project. I feel it is important that I am writing proper code before
moving onto learning modules and such.
On 5 November 2010 08:32, Mark Tolonen
metolone+gm...@gmail.commetolone%2bgm...@gmail.com
wrote:
Glen Clark gle...@gmail.com wrote in message
news:aanlktimabbj8ae35q3ao9+xzbvtnyzbz3wrudahmn...@mail.gmail.com...
Hello,
I have completed my first python script. This is after watching a video
guide on python and is my first attempt at writing code in python. While
the
code is not very useful I got the idea for it when googling python
projects
for beginners.
The idea was to create a script that asked the user to input a list of
names
and allow the user to change a name if he wanted before confirming the
entries.
I tried to incorporate what I had learnt from the videos, such as
conditionals, error handling, functions etc... and write it how I would
write code in future.
Please if you are kind enougth to take the time to provide feedback I
would
appreciate that it is constructive :)
The script is here: http://bpaste.net/show/10658/
Your code is very readable...more so than some experienced people ;^)
A few suggestions (and assuming Python 3.X, since that's what it looks
like):
* list shadows a built-in type, and should not be used for variable
names. names would be more appropriate.
* input() return a string, so no need for str(input(...)).
* range(x) is equivalent to range(0,x).
* The two loops in InitiateEntries can be consolidated:
for In in range(NumItems):
names.append(input(Enter name {}: .format(In+1)))
Or using a list comprehension:
names = [input(Enter name {}: .format(In+1) for In in
range(NumItems)]
* Prefer for name in names: instead of using indexing, or for idx,name
in enumerate(names): if indexes are needed. Example:
for idx,name in enumerate(names):
print({}: {}.format(idx,name)
* Since 1-based indexing was used elsewhere to present names to the user,
the PrintEntries display code should also use idx+1.
* When returning a boolean value, you can simpify:
if confirmed == 'n':
return True
else:
return False
To:
return confirmed == 'n'
Also see PEP8 (http://www.python.org/dev/peps/pep-0008/) for Python's
suggested coding standard.
-Mark
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor