CaptainMark
September 6th, 2010, 11:22 AM
Im learning python (really early days still so go easy on me) and having trouble figuring out where the continue statement returns to. Heres my code so far, its a training thing so its a really stupid program.
#!/usr/bin/python3
# character creation
# a program that lets you edit attribute for a rpg character
# mark skinner 06/09/2010
# variables
stats={'strength':0,'health':0,'wisdom':0,'dexteri ty':0}
choice=None
freepoints=30
# user choice
while choice!=0:
print('''You have the following options:
0. Quit
1. Distribute points from scratch
2. Remove points from an attribute
3. Add points to an attribute
4. Veiw current point usage''')
choice=input('\nPlease enter your choice number. ')
# distribute points
if choice=='1':
freepoints=30
print('\nAll points have been reset.\nYou currently have',freepoints,'free points.\n\
If you use too many points you will start again. ')
input('Press enter to start. ')
for element in stats:
print('\nCurrent attribute:',element.title(),'\nAvailable points:',freepoints)
change=input('How many points would you like? ')
change=int(change)
stats[element]=change
freepoints-=change
print('The attribute',element,'is set to:',stats[element])
if freepoints<0:
print('\nYou have used too many points.\nAll points have been reset to zero. ')
for element in stats:
stats[element]=0
input('Press enter to continue. ')
continue
The thing im having trouble understanding is at the bottom i was expecting 'if freepoints<0' to print the message, reset the stats and return the user up to just after the line '# distibute points' ready to start entering points again but instead it returns to the main menu options and prints them again, where am i going wrong and how do i correct my code to do what i intended?
#!/usr/bin/python3
# character creation
# a program that lets you edit attribute for a rpg character
# mark skinner 06/09/2010
# variables
stats={'strength':0,'health':0,'wisdom':0,'dexteri ty':0}
choice=None
freepoints=30
# user choice
while choice!=0:
print('''You have the following options:
0. Quit
1. Distribute points from scratch
2. Remove points from an attribute
3. Add points to an attribute
4. Veiw current point usage''')
choice=input('\nPlease enter your choice number. ')
# distribute points
if choice=='1':
freepoints=30
print('\nAll points have been reset.\nYou currently have',freepoints,'free points.\n\
If you use too many points you will start again. ')
input('Press enter to start. ')
for element in stats:
print('\nCurrent attribute:',element.title(),'\nAvailable points:',freepoints)
change=input('How many points would you like? ')
change=int(change)
stats[element]=change
freepoints-=change
print('The attribute',element,'is set to:',stats[element])
if freepoints<0:
print('\nYou have used too many points.\nAll points have been reset to zero. ')
for element in stats:
stats[element]=0
input('Press enter to continue. ')
continue
The thing im having trouble understanding is at the bottom i was expecting 'if freepoints<0' to print the message, reset the stats and return the user up to just after the line '# distibute points' ready to start entering points again but instead it returns to the main menu options and prints them again, where am i going wrong and how do i correct my code to do what i intended?