How can I print all the multiples of 5 from 5 to 1,000,000
New to Python and having a hard time creating a for
loop or while
loop that'll give me an output of 5, 10 ,15, 20, ...
all the way to 1,000,000
.
python
add a comment |
New to Python and having a hard time creating a for
loop or while
loop that'll give me an output of 5, 10 ,15, 20, ...
all the way to 1,000,000
.
python
2
I think the pythonrange()
object is what you want.
– SuperShoot
Nov 26 '18 at 3:21
add a comment |
New to Python and having a hard time creating a for
loop or while
loop that'll give me an output of 5, 10 ,15, 20, ...
all the way to 1,000,000
.
python
New to Python and having a hard time creating a for
loop or while
loop that'll give me an output of 5, 10 ,15, 20, ...
all the way to 1,000,000
.
python
python
edited Nov 26 '18 at 5:20
SuperShoot
1,993921
1,993921
asked Nov 26 '18 at 3:20
Robin HartleyRobin Hartley
12
12
2
I think the pythonrange()
object is what you want.
– SuperShoot
Nov 26 '18 at 3:21
add a comment |
2
I think the pythonrange()
object is what you want.
– SuperShoot
Nov 26 '18 at 3:21
2
2
I think the python
range()
object is what you want.– SuperShoot
Nov 26 '18 at 3:21
I think the python
range()
object is what you want.– SuperShoot
Nov 26 '18 at 3:21
add a comment |
3 Answers
3
active
oldest
votes
Use range
(note your doing to a million which is gonna take a while):
print(list(range(5,1000005,5)))
This doesn't answer the "question" which explicitly "asks" for afor
orwhile
loop...
– Julien
Nov 26 '18 at 3:42
add a comment |
total = 5
while total <= 1000000:
print(total)
total = total + 5
add a comment |
Try this
for i in range(0,1000000,5):
print(i)
This will print every time it goes up by 5.
The range()
function works like range(start, stop, step)
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%2f53474379%2fhow-can-i-print-all-the-multiples-of-5-from-5-to-1-000-000%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use range
(note your doing to a million which is gonna take a while):
print(list(range(5,1000005,5)))
This doesn't answer the "question" which explicitly "asks" for afor
orwhile
loop...
– Julien
Nov 26 '18 at 3:42
add a comment |
Use range
(note your doing to a million which is gonna take a while):
print(list(range(5,1000005,5)))
This doesn't answer the "question" which explicitly "asks" for afor
orwhile
loop...
– Julien
Nov 26 '18 at 3:42
add a comment |
Use range
(note your doing to a million which is gonna take a while):
print(list(range(5,1000005,5)))
Use range
(note your doing to a million which is gonna take a while):
print(list(range(5,1000005,5)))
answered Nov 26 '18 at 3:24
U9-ForwardU9-Forward
17.1k51743
17.1k51743
This doesn't answer the "question" which explicitly "asks" for afor
orwhile
loop...
– Julien
Nov 26 '18 at 3:42
add a comment |
This doesn't answer the "question" which explicitly "asks" for afor
orwhile
loop...
– Julien
Nov 26 '18 at 3:42
This doesn't answer the "question" which explicitly "asks" for a
for
or while
loop...– Julien
Nov 26 '18 at 3:42
This doesn't answer the "question" which explicitly "asks" for a
for
or while
loop...– Julien
Nov 26 '18 at 3:42
add a comment |
total = 5
while total <= 1000000:
print(total)
total = total + 5
add a comment |
total = 5
while total <= 1000000:
print(total)
total = total + 5
add a comment |
total = 5
while total <= 1000000:
print(total)
total = total + 5
total = 5
while total <= 1000000:
print(total)
total = total + 5
answered Nov 26 '18 at 3:24
John GordonJohn Gordon
10.5k51831
10.5k51831
add a comment |
add a comment |
Try this
for i in range(0,1000000,5):
print(i)
This will print every time it goes up by 5.
The range()
function works like range(start, stop, step)
add a comment |
Try this
for i in range(0,1000000,5):
print(i)
This will print every time it goes up by 5.
The range()
function works like range(start, stop, step)
add a comment |
Try this
for i in range(0,1000000,5):
print(i)
This will print every time it goes up by 5.
The range()
function works like range(start, stop, step)
Try this
for i in range(0,1000000,5):
print(i)
This will print every time it goes up by 5.
The range()
function works like range(start, stop, step)
answered Nov 26 '18 at 3:29
exeexe
13514
13514
add a comment |
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%2f53474379%2fhow-can-i-print-all-the-multiples-of-5-from-5-to-1-000-000%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
2
I think the python
range()
object is what you want.– SuperShoot
Nov 26 '18 at 3:21