TypeError: 'int' object is not iterable while calling a dictionary
I created a dictionary named weapons and armors that contained the item names and its gold price, the ellipses are not in the code it's just because the items are too many:
weapons = {'Rusty Sword':20,'Great Sword':120,'Steel Sword':70,'Dagger':0, .... 'Chain Armlet':0,'God Fist':0}
armors = {'Clothes':20,'Leather Vest':20,'Chain Mail':50,'Cloak':0,'Robe':0,..... 'Kamui Sennetsu':0,'Susanoo':0}
class Player:
def __init__(self, name):
self.name = name
self.maxhealth = 50
self.health = self.maxhealth
self.attack = 20
self.base_attack = 10
self.defense = 5
self.base_defense = 0
self.gold = 100
self.pots = 0
self.armor = ['Clothes']
self.curarmor = ['Clothes']
self.weap = ['Rusty Sword']
self.curweap = ['Rusty Sword']
Whenever I run this code my code, it says "TypeError: 'int' object is not iterable". I am stuck, here is the code it calls back:
for armor in PlayerIG.armor: <----- here is the callback
print ('>',armor)
print ('Exit')
option = input('--> ')
But in the weapons code, it works perfectly fine and the only difference is the call names:
for weapon in PlayerIG.weap:
print ('>',weapon)
print ('Exit')
option = input('--> ')
What should I do?
python python-3.x
|
show 2 more comments
I created a dictionary named weapons and armors that contained the item names and its gold price, the ellipses are not in the code it's just because the items are too many:
weapons = {'Rusty Sword':20,'Great Sword':120,'Steel Sword':70,'Dagger':0, .... 'Chain Armlet':0,'God Fist':0}
armors = {'Clothes':20,'Leather Vest':20,'Chain Mail':50,'Cloak':0,'Robe':0,..... 'Kamui Sennetsu':0,'Susanoo':0}
class Player:
def __init__(self, name):
self.name = name
self.maxhealth = 50
self.health = self.maxhealth
self.attack = 20
self.base_attack = 10
self.defense = 5
self.base_defense = 0
self.gold = 100
self.pots = 0
self.armor = ['Clothes']
self.curarmor = ['Clothes']
self.weap = ['Rusty Sword']
self.curweap = ['Rusty Sword']
Whenever I run this code my code, it says "TypeError: 'int' object is not iterable". I am stuck, here is the code it calls back:
for armor in PlayerIG.armor: <----- here is the callback
print ('>',armor)
print ('Exit')
option = input('--> ')
But in the weapons code, it works perfectly fine and the only difference is the call names:
for weapon in PlayerIG.weap:
print ('>',weapon)
print ('Exit')
option = input('--> ')
What should I do?
python python-3.x
5
What isplayerIG
?
– Jon Clements♦
Nov 14 '18 at 13:59
4
Please post a Minimal, Complete, and Verifiable example, there's too many unknown variables here
– UnholySheep
Nov 14 '18 at 13:59
1
Please give a class definition of PlayerIG.
– The Pjot
Nov 14 '18 at 13:59
A full stack trace would also be helpful.
– Hampus Larsson
Nov 14 '18 at 14:10
Sorry bout that, I added the class so you can see
– Shun Lushiko
Nov 15 '18 at 11:59
|
show 2 more comments
I created a dictionary named weapons and armors that contained the item names and its gold price, the ellipses are not in the code it's just because the items are too many:
weapons = {'Rusty Sword':20,'Great Sword':120,'Steel Sword':70,'Dagger':0, .... 'Chain Armlet':0,'God Fist':0}
armors = {'Clothes':20,'Leather Vest':20,'Chain Mail':50,'Cloak':0,'Robe':0,..... 'Kamui Sennetsu':0,'Susanoo':0}
class Player:
def __init__(self, name):
self.name = name
self.maxhealth = 50
self.health = self.maxhealth
self.attack = 20
self.base_attack = 10
self.defense = 5
self.base_defense = 0
self.gold = 100
self.pots = 0
self.armor = ['Clothes']
self.curarmor = ['Clothes']
self.weap = ['Rusty Sword']
self.curweap = ['Rusty Sword']
Whenever I run this code my code, it says "TypeError: 'int' object is not iterable". I am stuck, here is the code it calls back:
for armor in PlayerIG.armor: <----- here is the callback
print ('>',armor)
print ('Exit')
option = input('--> ')
But in the weapons code, it works perfectly fine and the only difference is the call names:
for weapon in PlayerIG.weap:
print ('>',weapon)
print ('Exit')
option = input('--> ')
What should I do?
python python-3.x
I created a dictionary named weapons and armors that contained the item names and its gold price, the ellipses are not in the code it's just because the items are too many:
weapons = {'Rusty Sword':20,'Great Sword':120,'Steel Sword':70,'Dagger':0, .... 'Chain Armlet':0,'God Fist':0}
armors = {'Clothes':20,'Leather Vest':20,'Chain Mail':50,'Cloak':0,'Robe':0,..... 'Kamui Sennetsu':0,'Susanoo':0}
class Player:
def __init__(self, name):
self.name = name
self.maxhealth = 50
self.health = self.maxhealth
self.attack = 20
self.base_attack = 10
self.defense = 5
self.base_defense = 0
self.gold = 100
self.pots = 0
self.armor = ['Clothes']
self.curarmor = ['Clothes']
self.weap = ['Rusty Sword']
self.curweap = ['Rusty Sword']
Whenever I run this code my code, it says "TypeError: 'int' object is not iterable". I am stuck, here is the code it calls back:
for armor in PlayerIG.armor: <----- here is the callback
print ('>',armor)
print ('Exit')
option = input('--> ')
But in the weapons code, it works perfectly fine and the only difference is the call names:
for weapon in PlayerIG.weap:
print ('>',weapon)
print ('Exit')
option = input('--> ')
What should I do?
python python-3.x
python python-3.x
edited Nov 15 '18 at 11:59
Shun Lushiko
asked Nov 14 '18 at 13:57
Shun LushikoShun Lushiko
108
108
5
What isplayerIG
?
– Jon Clements♦
Nov 14 '18 at 13:59
4
Please post a Minimal, Complete, and Verifiable example, there's too many unknown variables here
– UnholySheep
Nov 14 '18 at 13:59
1
Please give a class definition of PlayerIG.
– The Pjot
Nov 14 '18 at 13:59
A full stack trace would also be helpful.
– Hampus Larsson
Nov 14 '18 at 14:10
Sorry bout that, I added the class so you can see
– Shun Lushiko
Nov 15 '18 at 11:59
|
show 2 more comments
5
What isplayerIG
?
– Jon Clements♦
Nov 14 '18 at 13:59
4
Please post a Minimal, Complete, and Verifiable example, there's too many unknown variables here
– UnholySheep
Nov 14 '18 at 13:59
1
Please give a class definition of PlayerIG.
– The Pjot
Nov 14 '18 at 13:59
A full stack trace would also be helpful.
– Hampus Larsson
Nov 14 '18 at 14:10
Sorry bout that, I added the class so you can see
– Shun Lushiko
Nov 15 '18 at 11:59
5
5
What is
playerIG
?– Jon Clements♦
Nov 14 '18 at 13:59
What is
playerIG
?– Jon Clements♦
Nov 14 '18 at 13:59
4
4
Please post a Minimal, Complete, and Verifiable example, there's too many unknown variables here
– UnholySheep
Nov 14 '18 at 13:59
Please post a Minimal, Complete, and Verifiable example, there's too many unknown variables here
– UnholySheep
Nov 14 '18 at 13:59
1
1
Please give a class definition of PlayerIG.
– The Pjot
Nov 14 '18 at 13:59
Please give a class definition of PlayerIG.
– The Pjot
Nov 14 '18 at 13:59
A full stack trace would also be helpful.
– Hampus Larsson
Nov 14 '18 at 14:10
A full stack trace would also be helpful.
– Hampus Larsson
Nov 14 '18 at 14:10
Sorry bout that, I added the class so you can see
– Shun Lushiko
Nov 15 '18 at 11:59
Sorry bout that, I added the class so you can see
– Shun Lushiko
Nov 15 '18 at 11:59
|
show 2 more comments
1 Answer
1
active
oldest
votes
Since you haven't provided enough for me to work with, I will assume that your problem is that PlayerIG.armor
's type is int
.
You can't iterate over an int.
This may be unwanted, so I reccomend you do some debugging, like print(PlayerIG.armor)
right before that loop to figure out what it is set to. Then try and figure out where you went wrong.
Are you sure you didn't mean PlayerIG.armors
?
Just a side note, dict
s are unordered, meaning that your weapons, (and armor when you get that working) will all print in the order they are stored in the memory.
Added the Player class, sorry bout that
– Shun Lushiko
Nov 15 '18 at 12:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301930%2ftypeerror-int-object-is-not-iterable-while-calling-a-dictionary%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Since you haven't provided enough for me to work with, I will assume that your problem is that PlayerIG.armor
's type is int
.
You can't iterate over an int.
This may be unwanted, so I reccomend you do some debugging, like print(PlayerIG.armor)
right before that loop to figure out what it is set to. Then try and figure out where you went wrong.
Are you sure you didn't mean PlayerIG.armors
?
Just a side note, dict
s are unordered, meaning that your weapons, (and armor when you get that working) will all print in the order they are stored in the memory.
Added the Player class, sorry bout that
– Shun Lushiko
Nov 15 '18 at 12:00
add a comment |
Since you haven't provided enough for me to work with, I will assume that your problem is that PlayerIG.armor
's type is int
.
You can't iterate over an int.
This may be unwanted, so I reccomend you do some debugging, like print(PlayerIG.armor)
right before that loop to figure out what it is set to. Then try and figure out where you went wrong.
Are you sure you didn't mean PlayerIG.armors
?
Just a side note, dict
s are unordered, meaning that your weapons, (and armor when you get that working) will all print in the order they are stored in the memory.
Added the Player class, sorry bout that
– Shun Lushiko
Nov 15 '18 at 12:00
add a comment |
Since you haven't provided enough for me to work with, I will assume that your problem is that PlayerIG.armor
's type is int
.
You can't iterate over an int.
This may be unwanted, so I reccomend you do some debugging, like print(PlayerIG.armor)
right before that loop to figure out what it is set to. Then try and figure out where you went wrong.
Are you sure you didn't mean PlayerIG.armors
?
Just a side note, dict
s are unordered, meaning that your weapons, (and armor when you get that working) will all print in the order they are stored in the memory.
Since you haven't provided enough for me to work with, I will assume that your problem is that PlayerIG.armor
's type is int
.
You can't iterate over an int.
This may be unwanted, so I reccomend you do some debugging, like print(PlayerIG.armor)
right before that loop to figure out what it is set to. Then try and figure out where you went wrong.
Are you sure you didn't mean PlayerIG.armors
?
Just a side note, dict
s are unordered, meaning that your weapons, (and armor when you get that working) will all print in the order they are stored in the memory.
edited Nov 14 '18 at 15:25
answered Nov 14 '18 at 15:20
QwertyQwerty
845619
845619
Added the Player class, sorry bout that
– Shun Lushiko
Nov 15 '18 at 12:00
add a comment |
Added the Player class, sorry bout that
– Shun Lushiko
Nov 15 '18 at 12:00
Added the Player class, sorry bout that
– Shun Lushiko
Nov 15 '18 at 12:00
Added the Player class, sorry bout that
– Shun Lushiko
Nov 15 '18 at 12:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301930%2ftypeerror-int-object-is-not-iterable-while-calling-a-dictionary%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
5
What is
playerIG
?– Jon Clements♦
Nov 14 '18 at 13:59
4
Please post a Minimal, Complete, and Verifiable example, there's too many unknown variables here
– UnholySheep
Nov 14 '18 at 13:59
1
Please give a class definition of PlayerIG.
– The Pjot
Nov 14 '18 at 13:59
A full stack trace would also be helpful.
– Hampus Larsson
Nov 14 '18 at 14:10
Sorry bout that, I added the class so you can see
– Shun Lushiko
Nov 15 '18 at 11:59