Posts: 2
Threads: 1
Joined: Mar 2017
Mar-21-2017, 03:53 PM
(This post was last modified: Mar-21-2017, 06:19 PM by Larz60+.)
I have been coding python 3 using repl.it, and I have this code. To make everything work I had it print to make sure it worked. For some reason, Stats wont split as part of health.
Stats = [5, 5, 5, 5, 5],
Head = 'Leather Cap',
Torso = 'Leather Vambrace',
Arms = 'Leather Shoulder Pads',
LeftHand = 'Iron Longsword',
RightHand = 'Wooden Buckler',
Legs = 'Leather Pants',
Feet = 'Leather Boots',
PlayerOneStats = {}
PlayerOneHealthCap = Stats[0]
print(PlayerOneHealthCap) Help please!
Moderator: Added code tags for you this time. Please use in future.
Posts: 5,150
Threads: 396
Joined: Sep 2016
Quote:Stats wont split as part of health
stats is a list. It is already split. More info..
Recommended Tutorials:
Posts: 2
Threads: 1
Joined: Mar 2017
What I mean is that when it prints the health part it still print the entire list of 5s without taking just the first one or multiplying it. How can I remedy this?
Posts: 5,150
Threads: 396
Joined: Sep 2016
list[0] will return the first element of the list
>>> stats = [1,2,3,4,5,6,7,8]
>>> stats[0]
1 Quote:Stats = [5, 5, 5, 5, 5],
Head = 'Leather Cap',
Torso = 'Leather Vambrace',
Arms = 'Leather Shoulder Pads',
LeftHand = 'Iron Longsword',
RightHand = 'Wooden Buckler',
Legs = 'Leather Pants',
Feet = 'Leather Boots',
What is up with the commas after each line?
Recommended Tutorials:
Posts: 687
Threads: 37
Joined: Sep 2016
Mar-21-2017, 04:29 PM
(This post was last modified: Mar-21-2017, 04:29 PM by Ofnuts.)
You have an extra comma at the end of Stats = [5, 5, 5, 5, 5], so Python thinks Stats is a one-element tuple, whose first element is [5, 5, 5, 5, 5] . So Stats[0] is [5, 5, 5, 5, 5] .... Remove the comma and it should work as expected.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Posts: 5,150
Threads: 396
Joined: Sep 2016
|