I need to loops from 0 to a var [python]
up vote
-5
down vote
favorite
CardAmount = input(">?")
while len(dogs) > 0:
for [im not sure how to only do this for (CardAmount) amount of times]
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
dogs is a list with 30 names and 4 attributes on each,
I need the player to be able to choose the amount of cards but for now i have to do all of them, anyone know how?
python
add a comment |
up vote
-5
down vote
favorite
CardAmount = input(">?")
while len(dogs) > 0:
for [im not sure how to only do this for (CardAmount) amount of times]
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
dogs is a list with 30 names and 4 attributes on each,
I need the player to be able to choose the amount of cards but for now i have to do all of them, anyone know how?
python
Possible duplicate of How to loop x amount of times based on user input
– user10455554
Nov 20 at 9:52
Use therange
builtin as infor x in range(CardAmoun):
.
– MisterMiyagi
Nov 20 at 9:54
1
you should use lower_case_with_underscores for variable names instead of CamelCase : python.org/dev/peps/pep-0008/#naming-conventions
– Corentin Limier
Nov 20 at 9:57
add a comment |
up vote
-5
down vote
favorite
up vote
-5
down vote
favorite
CardAmount = input(">?")
while len(dogs) > 0:
for [im not sure how to only do this for (CardAmount) amount of times]
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
dogs is a list with 30 names and 4 attributes on each,
I need the player to be able to choose the amount of cards but for now i have to do all of them, anyone know how?
python
CardAmount = input(">?")
while len(dogs) > 0:
for [im not sure how to only do this for (CardAmount) amount of times]
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
dogs is a list with 30 names and 4 attributes on each,
I need the player to be able to choose the amount of cards but for now i have to do all of them, anyone know how?
python
python
asked Nov 20 at 9:47
Ben Goodall
12
12
Possible duplicate of How to loop x amount of times based on user input
– user10455554
Nov 20 at 9:52
Use therange
builtin as infor x in range(CardAmoun):
.
– MisterMiyagi
Nov 20 at 9:54
1
you should use lower_case_with_underscores for variable names instead of CamelCase : python.org/dev/peps/pep-0008/#naming-conventions
– Corentin Limier
Nov 20 at 9:57
add a comment |
Possible duplicate of How to loop x amount of times based on user input
– user10455554
Nov 20 at 9:52
Use therange
builtin as infor x in range(CardAmoun):
.
– MisterMiyagi
Nov 20 at 9:54
1
you should use lower_case_with_underscores for variable names instead of CamelCase : python.org/dev/peps/pep-0008/#naming-conventions
– Corentin Limier
Nov 20 at 9:57
Possible duplicate of How to loop x amount of times based on user input
– user10455554
Nov 20 at 9:52
Possible duplicate of How to loop x amount of times based on user input
– user10455554
Nov 20 at 9:52
Use the
range
builtin as in for x in range(CardAmoun):
.– MisterMiyagi
Nov 20 at 9:54
Use the
range
builtin as in for x in range(CardAmoun):
.– MisterMiyagi
Nov 20 at 9:54
1
1
you should use lower_case_with_underscores for variable names instead of CamelCase : python.org/dev/peps/pep-0008/#naming-conventions
– Corentin Limier
Nov 20 at 9:57
you should use lower_case_with_underscores for variable names instead of CamelCase : python.org/dev/peps/pep-0008/#naming-conventions
– Corentin Limier
Nov 20 at 9:57
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
for i in range(CardAmount):
# do stuff CardAmount times
add a comment |
up vote
0
down vote
You can use the range()
function. If I understand correctly, your code should be
CardAmount = input(">?")
while len(dogs) > 0:
for i in range(CardAmount):
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
For the details see the documentation.
dumptext.com/Vryd7IZS dumptext.com/JpWnb9fG Not sure why its saying its not defined?
– Ben Goodall
Nov 20 at 10:06
Probably because the variable is initialized inside the try statement
– Riccardo Orlando
Nov 20 at 10:14
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',
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%2f53390232%2fi-need-to-loops-from-0-to-a-var-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
for i in range(CardAmount):
# do stuff CardAmount times
add a comment |
up vote
0
down vote
for i in range(CardAmount):
# do stuff CardAmount times
add a comment |
up vote
0
down vote
up vote
0
down vote
for i in range(CardAmount):
# do stuff CardAmount times
for i in range(CardAmount):
# do stuff CardAmount times
answered Nov 20 at 9:53
Maiki Bodhisattva
687
687
add a comment |
add a comment |
up vote
0
down vote
You can use the range()
function. If I understand correctly, your code should be
CardAmount = input(">?")
while len(dogs) > 0:
for i in range(CardAmount):
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
For the details see the documentation.
dumptext.com/Vryd7IZS dumptext.com/JpWnb9fG Not sure why its saying its not defined?
– Ben Goodall
Nov 20 at 10:06
Probably because the variable is initialized inside the try statement
– Riccardo Orlando
Nov 20 at 10:14
add a comment |
up vote
0
down vote
You can use the range()
function. If I understand correctly, your code should be
CardAmount = input(">?")
while len(dogs) > 0:
for i in range(CardAmount):
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
For the details see the documentation.
dumptext.com/Vryd7IZS dumptext.com/JpWnb9fG Not sure why its saying its not defined?
– Ben Goodall
Nov 20 at 10:06
Probably because the variable is initialized inside the try statement
– Riccardo Orlando
Nov 20 at 10:14
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use the range()
function. If I understand correctly, your code should be
CardAmount = input(">?")
while len(dogs) > 0:
for i in range(CardAmount):
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
For the details see the documentation.
You can use the range()
function. If I understand correctly, your code should be
CardAmount = input(">?")
while len(dogs) > 0:
for i in range(CardAmount):
playersDeck.append(dogs.pop(0))
computersDeck.append(dogs.pop(0))
For the details see the documentation.
answered Nov 20 at 9:54
Riccardo Orlando
75
75
dumptext.com/Vryd7IZS dumptext.com/JpWnb9fG Not sure why its saying its not defined?
– Ben Goodall
Nov 20 at 10:06
Probably because the variable is initialized inside the try statement
– Riccardo Orlando
Nov 20 at 10:14
add a comment |
dumptext.com/Vryd7IZS dumptext.com/JpWnb9fG Not sure why its saying its not defined?
– Ben Goodall
Nov 20 at 10:06
Probably because the variable is initialized inside the try statement
– Riccardo Orlando
Nov 20 at 10:14
dumptext.com/Vryd7IZS dumptext.com/JpWnb9fG Not sure why its saying its not defined?
– Ben Goodall
Nov 20 at 10:06
dumptext.com/Vryd7IZS dumptext.com/JpWnb9fG Not sure why its saying its not defined?
– Ben Goodall
Nov 20 at 10:06
Probably because the variable is initialized inside the try statement
– Riccardo Orlando
Nov 20 at 10:14
Probably because the variable is initialized inside the try statement
– Riccardo Orlando
Nov 20 at 10:14
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53390232%2fi-need-to-loops-from-0-to-a-var-python%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
Possible duplicate of How to loop x amount of times based on user input
– user10455554
Nov 20 at 9:52
Use the
range
builtin as infor x in range(CardAmoun):
.– MisterMiyagi
Nov 20 at 9:54
1
you should use lower_case_with_underscores for variable names instead of CamelCase : python.org/dev/peps/pep-0008/#naming-conventions
– Corentin Limier
Nov 20 at 9:57