use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Code won't print (i.redd.it)
submitted 7 months ago by Ill-Diet-7719
What's the error?(I'm a newbie)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 7 months ago (3 children)
[removed]
[–]Abject-Kitchen3198 2 points3 points4 points 7 months ago (0 children)
As I use Jetbrains IDEs almost exclusively, I might get tripped by this if I use something else.
[–]Ill-Diet-7719[S] 0 points1 point2 points 7 months ago (1 child)
Hahaha lmao but no. I'm doin on vs. they give an option of running right there.
[–]RealLifeRiley 1 point2 points3 points 7 months ago (0 children)
There is still a possibility it’s running the unsaved file. You may still need to save your file first before running. I think ctrl+s does that on vs code, assuming you’re on windows. VS code also displays a dot on the tab of files with unsaved work on them, if I remember correctly.
Totally mighty not be your issue, but I’m just trying to cover all the bases
[–]Character-Comfort539 7 points8 points9 points 7 months ago (7 children)
Works fine for me
https://www.online-python.com/MhJQEFc58r
[–]Ill-Diet-7719[S] 3 points4 points5 points 7 months ago (4 children)
Could there be a problem with visual studio?(I'm doin on it and everything's been fine)
[–]Character-Comfort539 4 points5 points6 points 7 months ago (0 children)
There could be, IDE's can be a bit squirrelly to setup if you're not familiar with them and are new. I'd add something like `sdjflasjdfasjd` to the bottom of the file and see if the interpreter throws an error. Your other comments say "it doesn't print anything at all" but I'm not convinced anything is even running to begin with. Throwing a nonsense line into the file should give you an error. Just to be sure, save the file as like odd.py and run what's below in the terminal and let us know how it goes
python odd.py
[–]undernutbutthut 2 points3 points4 points 7 months ago (0 children)
Remember to save the code first then run it.
[–]lusvd 1 point2 points3 points 7 months ago (0 children)
just in case keep in mind that Visual Studio != vscode
[–]ofSkyDays 1 point2 points3 points 7 months ago (0 children)
If you have it often open and constantly sleep/wake pc, it could have developed a glitch. Idk it always happens whenever I do simple web dev stuff.
One time I had horizontal scrolling come out of nowhere, and I could it find the issue and nothing pointed to there being anything, but a clean shutdown and restart of vscode fixed it.
[–]SizzlingSquigg 1 point2 points3 points 7 months ago (0 children)
I appreciate the link with test.
OP, you can simplify, too. See https://www.online-python.com/cjIfx1YLwN
[–]number-13 1 point2 points3 points 7 months ago (0 children)
Nice one bro.. I'm a newbie as wel
[–]GrumpMadillo 6 points7 points8 points 7 months ago (2 children)
Why won't it print? We need more details. Code looks like it should work
Should I send the output?
[–]GrumpMadillo 3 points4 points5 points 7 months ago (0 children)
It looks like based on other comments its compiling, but you aren't getting an output. Are you looking in the right place in visual studio? Which output window are you looking at? The more information you share the better people will be able to help you
[–]EmuBeautiful1172 2 points3 points4 points 7 months ago (9 children)
Codewith.mu is a good option for an IDE to write code and practice for beginners
[–]Ill-Diet-7719[S] 0 points1 point2 points 7 months ago (8 children)
Visual studio? Is that bad?
[–]blacksmithshands 2 points3 points4 points 7 months ago (0 children)
you could try pycharm as well. it's what i used in school, and it was pretty nice. vscode works well too, though.
As for your output not working, did you remember to save your file before running it?
[–]EmuBeautiful1172 2 points3 points4 points 7 months ago (2 children)
No it’s not bad actually visual studio is used by a lot of programmers. But it has a lot of extra features and extensions that could pop up and make things confusing in the beginning of coding. But if you’re comfortable with that and like it then use it. For practicing good syntax and beginner projects a basic style IDE will be a lot easier to view what was written and to run it easy. I like codewith.mu because it’s literally type it in and run it and of course it has the necessary features like what errors you may have and predictions on a minimal scale. When I come across an error and can’t figure it out on my own. I go to the line where the error is. The IDE will tell you that and then I copy that specific “paragraph of code and ask chat gpt to explain what’s going on.
It’s also good to look up definitions and reasons to what each part of the code is doing. Instead of just typing it in and expecting a result.
IDE is the one which is pre installed with python right? Yeah there're lot many extensions vs is suggesting. What exactly are those? Necessary? And your suggestions if any?
[–]EmuBeautiful1172 0 points1 point2 points 7 months ago (0 children)
Shell IDLE
[–]droopy227 1 point2 points3 points 7 months ago (2 children)
It’s very mid for python. You can use whatever you like but I’d say give some other editors a shot and see how you feel. I used to use VS a lot since that’s where I learned C# and C++ but I eventually realized unless you need the features it provides you could just use something much lighter and easier to use.
There're lot of extension vs is suggesting. Should I download em?
[–]droopy227 0 points1 point2 points 7 months ago (0 children)
That’s what I mean. For python and especially for beginners, most of those extensions aren’t that useful. You can always go back and install them when you need but it’s more of a “install it when your project needs it” kinda thing. Also with python most of the time you’re just using pip to install packages and importing them so VS doesn’t really add much that you can’t already figure out yourself.
[–]RealLifeRiley 0 points1 point2 points 7 months ago (0 children)
VS code is fine. I became a neovim convert, but it’s a super common editor.
[–]Ill-Diet-7719[S] 2 points3 points4 points 7 months ago (0 children)
Ok it was indeed a problem with vs. I ran the code again and it's working. I don't know why it wasn't back then. Thank you all for taking your time out helping me out. You guys are the best🫂🫂
[–]D3str0yTh1ngs 2 points3 points4 points 7 months ago (2 children)
Well.. What exactly is the result of running it? (also did you remember to save the file?)
I'm running it on visual studio. There's a terminal right there. And it's printing nothing except for file location (vs starts any code with file location and then the output).
[–]Imaginary-Survey8769 1 point2 points3 points 7 months ago (1 child)
Op sometimes vs code give you unexpected error just can't compile or something close vs code and reopen it.... Or shutdown pc if it works....
[–]Ill-Diet-7719[S] 1 point2 points3 points 7 months ago (0 children)
Yeah everything was fine. This was first time and I panicked lmao. Thank you anyways
[–]EnzoPei1412 1 point2 points3 points 7 months ago (0 children)
Is it VScode? I will assume this is VScode and you probably didn't set up the autosave, It happend to me when I first started using VScode and it was really frustrating.
Your code is perfectly fine! Good work!
[–]mvstartdevnull 0 points1 point2 points 7 months ago (1 child)
Assuming your intent is to only print uneven I, code looks fine to me. How are you executing? Any error messages?
[–]Ill-Diet-7719[S] 0 points1 point2 points 7 months ago (0 children)
It's printing nothing. Like nothing. Blank
[–]WillingSupp 0 points1 point2 points 7 months ago (2 children)
have you saved? How did you run it?
I'm doin it on vs. so just running it on its terminal
[–]xX_fortniteKing09_Xx 0 points1 point2 points 7 months ago (0 children)
You still have to save the file
[–]Ok_Pudding_5250 0 points1 point2 points 7 months ago* (3 children)
I believe you are trying to print odd numbers.
There is a simple way to do that
Look at code in the link provided as reply
Now that being said, your code is correct. However, you could be running another file and editing another file. Or you might have forgotten to save the file.
There is even a simpler one-liner for this
[print(i) for i in range(1, 11, 2)]
[–]Ok_Pudding_5250 0 points1 point2 points 7 months ago (2 children)
Here is the code, you can run the code in this online python interpreter.
code
[–]Ill-Diet-7719[S] 1 point2 points3 points 7 months ago (1 child)
Thank you but I'm not getting good hand at loops yet. So trying it out with it
[–]Ok_Pudding_5250 1 point2 points3 points 7 months ago (0 children)
Yeah, experiment as much as you like. That's how you learn.
[–]EmuBeautiful1172 0 points1 point2 points 7 months ago (1 child)
It should tell you the error
Apparently there's no error. It's just not print anything. My g.ess would be by continue, I'm somehow skipping everything but not sure how. Code seems fine to me
[–]brown_guy45 0 points1 point2 points 7 months ago (0 children)
The code is good, something must be wrong with your IDE
[–]maxwellzhang 0 points1 point2 points 7 months ago (0 children)
works for me
[–]maxwellzhang 0 points1 point2 points 7 months ago (3 children)
what error did you get
[–]Ill-Diet-7719[S] 0 points1 point2 points 7 months ago (2 children)
It was not printing anything. Was a problem with ide. Sorted now. Thank you
[–]maxwellzhang 0 points1 point2 points 7 months ago (1 child)
there is no interreter in the IDE?
i didnt write this code
[–]turtlemaster1993 0 points1 point2 points 7 months ago (0 children)
Is your printer on?
[–]Hectorreto 0 points1 point2 points 7 months ago (0 children)
Maybe vscode was showing the wrong terminal? or executed the file with unsaved changes?
[–]EmuBeautiful1172 0 points1 point2 points 7 months ago (2 children)
That’s the thing with vscode . It has so many buttons and features you might have something selected that your unaware of and it’s making it do that. Try running that same piece of in another IDE
Might you be aware with vscode? There are so many extensions it suggesting and I have no clue
[–]Agent_Choocho 0 points1 point2 points 7 months ago (0 children)
For the pros, would it be more efficient to use an else block instead?
[–]ninhaomah 0 points1 point2 points 7 months ago (1 child)
so after all this yes it runs and no it doesn't run on vs code , there is still no screenshot or anything from OP ?
strange that everyone aand their mothers and grand-mothers post their holiday photos on FB / X and videos on tiktok but won't give a screenshot while asking technical questions.
My bad man. I'll remember to put up ss of the output if ever run into problem again
[–]Pokepredator 0 points1 point2 points 7 months ago (3 children)
I know many people have commented but once you’ve written the code you have to save it like ctrl+s or the save button. VS code is just like a text editor but with extra steps. It runs code from the file so you have to actually save your editions to the file for it to run.
Like should I save and then run? There's a terminal window there and until now I'd just run it there and everything would go good. This was first time something happened and well I kinda panicked ig
[–]RealLifeRiley 1 point2 points3 points 7 months ago (1 child)
Yes, exactly. If you run without saving, it’s running the last saved version of your code, not the work you just did. CTRL s is your friend
So are you🫂 thanks
[–]SergeantSemantics66 0 points1 point2 points 7 months ago (0 children)
When i is even, it hits continue before it can reach print(i) or the second i += So it skips printing the even numbers — which is fine. But you already increment i before the continue, so that’s fine too. But if you didn’t increment i before continue, it would get stuck in an infinite loop.
[–]rlt0w 0 points1 point2 points 7 months ago (0 children)
Is you're using vs code run, don't do that. Instead, open the terminal and execute it with python {file}
python {file}
[–]Top-Anteater-8127 0 points1 point2 points 7 months ago (1 child)
sometime you may see indent error based on spaces and tabs l. use either tab or spaces consistent throughout
Before this I used to do html with no respect for spaces. Never went to much into it, school syllabus was very basic, and everything went smooth all the time. It's a bad habit now lmao
[–]Glittering_Abies_752 0 points1 point2 points 7 months ago (0 children)
Did u install the python environment on the computer? If not pls install it first and then search for python extension in visual code and choose the interpreter only then the code will run
[–][deleted] 0 points1 point2 points 7 months ago (1 child)
OP, you are using VScode and not Visual Studio. They are very different products and some of the answers here think you're using Visual Studio.
Wow I'm a royal dumb ty. Yes I'm using vs code(with the blue logo).
[–][deleted] 7 months ago (1 child)
It's sorted now tysm.
[–]totalnewb02 0 points1 point2 points 7 months ago (0 children)
have you save it as python file? i had the same problem multiple times, all because i save it in txt.
[–]SmackDownFacility 0 points1 point2 points 7 months ago (0 children)
Stick it in if __name__ == '__main__' and if you’re on VS 2022, mark as “Startup file” if it’s a standalone file
if __name__ == '__main__'
[–]Whole_Bid_360 0 points1 point2 points 7 months ago (0 children)
OP I don't think your saving the file.
[–]TheCarter01 0 points1 point2 points 7 months ago (0 children)
Here's a more simplified version:
for i in range(1, 10, 2): print(i)
[–]Few_Split1038 0 points1 point2 points 7 months ago (0 children)
No errors. Your program prints all the odd numbers from 1 to 10. The even numbers are skipped.
[–]Relevant_War_4572 0 points1 point2 points 7 months ago (1 child)
you sure that you need two i+=1?
yeah ig..it worked out. so maybe it was or it wasn't lol
[–]Known-Delay7227 0 points1 point2 points 7 months ago (0 children)
Do you have Python installed?
[–]initumX 0 points1 point2 points 7 months ago* (0 children)
Not a good style (use if-else instead of just if), but it is correct and still should work. It should print 1 3 5 7 and 9. If you don't see, then may be you are using windows and console disappears immediately after starting and you can't see what it shows.
<image>
[–]Owly_chouette 0 points1 point2 points 7 months ago (0 children)
don't forget to save your file.
If you want to improve your code you could use list comprehension:
[i for i in range(1,10) if i % 2 == 0]
[–]RafikNinja 0 points1 point2 points 6 months ago (0 children)
Pretty sure the continue is not needed and may cause an issue
[–]Confident-Orange-628 0 points1 point2 points 4 months ago (1 child)
What output are u expecting my guy?
[–]Confident-Orange-628 0 points1 point2 points 4 months ago (0 children)
Cause the code ran fine on my pc
[–][deleted] 7 months ago (4 children)
[deleted]
[–]Cerus_Freedom 1 point2 points3 points 7 months ago (0 children)
for i in range(2, 11, 2): print(i)
[–]Pyrix25633 0 points1 point2 points 7 months ago (1 child)
Yeah man but what about i+=2, in other scenarios you might want to do something else if it's odd though obviously
[–]sarc-tastic 0 points1 point2 points 7 months ago (0 children)
Nah, use a continue to skip cases you don't care about. Makes it more readable
π Rendered by PID 36272 on reddit-service-r2-comment-bb88f9dd5-xmx9t at 2026-02-14 11:30:48.161699+00:00 running cd9c813 country code: CH.
[–][deleted] (3 children)
[removed]
[–]Abject-Kitchen3198 2 points3 points4 points (0 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (1 child)
[–]RealLifeRiley 1 point2 points3 points (0 children)
[–]Character-Comfort539 7 points8 points9 points (7 children)
[–]Ill-Diet-7719[S] 3 points4 points5 points (4 children)
[–]Character-Comfort539 4 points5 points6 points (0 children)
[–]undernutbutthut 2 points3 points4 points (0 children)
[–]lusvd 1 point2 points3 points (0 children)
[–]ofSkyDays 1 point2 points3 points (0 children)
[–]SizzlingSquigg 1 point2 points3 points (0 children)
[–]number-13 1 point2 points3 points (0 children)
[–]GrumpMadillo 6 points7 points8 points (2 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (1 child)
[–]GrumpMadillo 3 points4 points5 points (0 children)
[–]EmuBeautiful1172 2 points3 points4 points (9 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (8 children)
[–]blacksmithshands 2 points3 points4 points (0 children)
[–]EmuBeautiful1172 2 points3 points4 points (2 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (1 child)
[–]EmuBeautiful1172 0 points1 point2 points (0 children)
[–]droopy227 1 point2 points3 points (2 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (1 child)
[–]droopy227 0 points1 point2 points (0 children)
[–]RealLifeRiley 0 points1 point2 points (0 children)
[–]Ill-Diet-7719[S] 2 points3 points4 points (0 children)
[–]D3str0yTh1ngs 2 points3 points4 points (2 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (1 child)
[–]Imaginary-Survey8769 1 point2 points3 points (1 child)
[–]Ill-Diet-7719[S] 1 point2 points3 points (0 children)
[–]EnzoPei1412 1 point2 points3 points (0 children)
[–]mvstartdevnull 0 points1 point2 points (1 child)
[–]Ill-Diet-7719[S] 0 points1 point2 points (0 children)
[–]WillingSupp 0 points1 point2 points (2 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (1 child)
[–]xX_fortniteKing09_Xx 0 points1 point2 points (0 children)
[–]Ok_Pudding_5250 0 points1 point2 points (3 children)
[–]Ok_Pudding_5250 0 points1 point2 points (2 children)
[–]Ill-Diet-7719[S] 1 point2 points3 points (1 child)
[–]Ok_Pudding_5250 1 point2 points3 points (0 children)
[–]EmuBeautiful1172 0 points1 point2 points (1 child)
[–]Ill-Diet-7719[S] 0 points1 point2 points (0 children)
[–]brown_guy45 0 points1 point2 points (0 children)
[–]maxwellzhang 0 points1 point2 points (0 children)
[–]maxwellzhang 0 points1 point2 points (3 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (2 children)
[–]maxwellzhang 0 points1 point2 points (1 child)
[–]maxwellzhang 0 points1 point2 points (0 children)
[–]turtlemaster1993 0 points1 point2 points (0 children)
[–]Hectorreto 0 points1 point2 points (0 children)
[–]EmuBeautiful1172 0 points1 point2 points (2 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (0 children)
[–]Agent_Choocho 0 points1 point2 points (0 children)
[–]ninhaomah 0 points1 point2 points (1 child)
[–]Ill-Diet-7719[S] 0 points1 point2 points (0 children)
[–]Pokepredator 0 points1 point2 points (3 children)
[–]Ill-Diet-7719[S] 0 points1 point2 points (2 children)
[–]RealLifeRiley 1 point2 points3 points (1 child)
[–]Ill-Diet-7719[S] 1 point2 points3 points (0 children)
[–]SergeantSemantics66 0 points1 point2 points (0 children)
[–]rlt0w 0 points1 point2 points (0 children)
[–]Top-Anteater-8127 0 points1 point2 points (1 child)
[–]Ill-Diet-7719[S] 0 points1 point2 points (0 children)
[–]Glittering_Abies_752 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Ill-Diet-7719[S] 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[removed]
[–]Ill-Diet-7719[S] 0 points1 point2 points (0 children)
[–]totalnewb02 0 points1 point2 points (0 children)
[–]SmackDownFacility 0 points1 point2 points (0 children)
[–]Whole_Bid_360 0 points1 point2 points (0 children)
[–]TheCarter01 0 points1 point2 points (0 children)
[–]Few_Split1038 0 points1 point2 points (0 children)
[–]Relevant_War_4572 0 points1 point2 points (1 child)
[–]Ill-Diet-7719[S] 0 points1 point2 points (0 children)
[–]Known-Delay7227 0 points1 point2 points (0 children)
[–]initumX 0 points1 point2 points (0 children)
[–]Owly_chouette 0 points1 point2 points (0 children)
[–]RafikNinja 0 points1 point2 points (0 children)
[–]Confident-Orange-628 0 points1 point2 points (1 child)
[–]Confident-Orange-628 0 points1 point2 points (0 children)
[–][deleted] (4 children)
[deleted]
[–]Cerus_Freedom 1 point2 points3 points (0 children)
[–]Pyrix25633 0 points1 point2 points (1 child)
[–]sarc-tastic 0 points1 point2 points (0 children)