
January 3rd, 2013, 07:25 PM
|
 |
Contributing User
|
|
|
|
We abhor duplicate code. This must have been a nightmare to write. "Gotta make the change in 4 places. OH NO!"
You have 4 cases all the same except for the attribute name and which lists are used. Encapsulate that into a function.
You have many prompts with validity tests. Again, encapsulate into a function.
I started rewriting as
Code:
stat_pool = ['|']*30
strength = []
health = []
wisdom = []
dexterity = []
choice = None
def prompt(message,validSet,tries,failureChoice):
M = message
result = failureChoice
for i in range(tries):
result = input(M)
if result in validSet:
return result
M = 'Please choose from %s'%str(validSet)
return failureChoice
while choice != "6":
attribute = prompt('(MAIN)Please choose an option: ',set('123456'),2,'6')
if attribute in set('1234'):
attribute_name = {
'1':'Strength','2':'Health','3':'Wisdom','4':'Dexterity'
}[attribute]
You may need a somewhat more clever prompt function with a validation function and exception handling when you get to the numbers representing amounts of stat points to transfer.
__________________
[code] Code tags[/code] are essential for python code!
|