"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