Hello Tutor,

Could somebody help me with below query?

Thanks
Marc

From: marc_eym...@hotmail.com
To: tutor@python.org
Subject: Beginner - list not returning correct variable value
Date: Thu, 13 Mar 2014 16:12:28 +0000




Hello Tutor,

I am a self-taught Python script beginner and I do it from the Michael Dawson 
Book.

In attached script, can somebody tell me why the values of the variables 
strenght_points, health_points, wisdom_points and dexterity_points stay at 0 
value when 'printing' their value from the list attributes[] when the 'for' 
loop at the bottom of the script runs.

I have commented out the script to highlight what causes me problem.

I hope this is clear enough a question.

Thanks for your help,
Marc
                                                                                
  
#Character role play
#you have 4 attributes and can assign/remove points to/from it
#use short story scripting to task with no MENU tree
#ignore calculus logic limitations

#set variables
strength_points = 0
health_points = 0
wisdom_points = 0
dexterity_points = 0
pool = 30
att_choice = None

attributes = [('strength',strength_points),
              ('health',health_points),
              ('wisdom',wisdom_points),
              ('dexterity',dexterity_points)]



print('Hello gladiator,\n')

print('you have the following attributes with no points:\n')

for i in attributes:
    att_name, points = i
    print(att_name,'\t',points)

input('\nPress ENTER to continue')

print('\nYou are now entrusted with a pool of 30 points to spend on them as you whish')
input('Press ENTER to continue')

print('\nUsing negative points will move them back to your pool of points')
input('Press ENTER to continue')

print('\nChose an attribute and add/remove points at your will:   ')

while att_choice != '0':

    #here proof that variables values are changing as expexted:
    print('here proof that variables values are changing as expected:')
    print(strength_points,health_points,wisdom_points,dexterity_points,pool)

    
    print('\n[1] stength [2] health [3] wisdom [4] dexterity [0] EXIT')
    att_choice = input('ENTER number here: ')

    if att_choice == '1':
      print('\nHow many strenght points you want to add (+) or remove (-) ?')
      points = int(input('Enter points here: '))
      strength_points += points
      pool -= points
    
    elif att_choice == '2':
      print('\nHow many health points you want to add (+) or remove (-) ?')
      points = int(input('Enter points here: '))
      health_points += points
      pool -= points

    elif att_choice == '3':
      print('\nHow many wisdom points you want to add (+) or remove (-) ?')
      points = int(input('Enter points here: '))
      wisdom_points += points
      pool -= points

    elif att_choice == '4':
      print('\nHow many dexterity points you want to add (+) or remove (-) ?')
      points = int(input('Enter points here: '))
      dexterity_points += points
      pool -= points

    elif att_choice == '0':
        print('Good Bye Gladiator!')
        break

    else:
        print('Sorry I don\'t understand your selection')
        input('Press ENTER to try again')

    print('\nYou have now the following attributes and points:\n')

    #here the loop does not return variable value as expected:
    for i in attributes:
        att_name, point = i
        print(att_name,'\t',point)

    input('\nPress ENTER to continue\n')

input('\nPress ENTER to exit')

    
      
        
      



 
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to