Note that there are some explanatory texts on larger screens.

plurals
  1. POValues from tuples named the same as user input in Python (Hard for me to explain, will update title if I can find a better way to express myself)
    text
    copied!<p>I am an extremely novice learner, I am taking a Python class to learn. This question has nothing to do with the class, just with a project I am working on as I am going through the class (I am working on a simple game, using concepts that I learn in class to update, expand, and clean up my code.)</p> <p>I am learning about Tuples, Lists, and Dictionaries at this time, and thought that simple tuples would clear up a lot of IF statements and streamline the code. However, I cannot get it to work exactly how I would like it to work.</p> <p>Basically I have a set of tuples for all of my classes (Note, these are training classifications, and not Python classes). They have different numbers in them, and then I have a tuple with a list of the names of all of the classes. At some point in the code, I ask for user input to determine a character's class. I would like to be able to use that input so I can extract (Is the correct term splice?) values from the tuple, say I want to add whatever value is in the third position of the tuple to another value. Right now I cannot get the user input associate with the tuple of the same name. Is there a way to do this?</p> <hr> <pre><code># Class list Apprentice = (6, 0, 0, 0, 0, 0, 0) Warrior = (12, 2, 0, 2, 0, 0, 0) Paladin = (14, 2, 0, 2, 1, 0, 1) Barbarian = (12, 6, 0, 3, -1, -1, -1) Blademaster = (10, 4, 4, 0, 0, 0, 0) Assassin = (8, 0, 8, -2, 0, 0, 0) Rogue = (8, 0, 4, 0, 0, 0, 0) Monk = (10, 2, 2, 2, 2, 2, -4) Bard = (8, 0, 0, 0, 0, 0, 4) Mage = (6, 0, 0, 0, 2, 2, 0) Priest = (6, 0, 0, 0, 1, 2, 1) Wizard = (4, -2, -2, -2, 6, 8, 0) Scholar = (6, -1, -1, 0, 4, 4, 0) Necromancer = (6, 0, 0, 0, 6, 6, -5) classList = ('Apprentice', 'Warrior', 'Priest', 'Mage', 'Wizard', 'Rogue', 'Bard', 'Paladin', 'Scholar', 'Necromancer', 'Barbarian', 'Blademaster', 'Assassin', 'Monk') </code></pre> <hr> <pre><code>validClass = False while validClass == False: charClass = raw_input('What type of training have you had (Class)? ') if charClass in classList: print '' validClass = True else: print 'That is not a valid class.' </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload