Python 3 help

Python 3 help.
I'm just a beginner with Python, i made this loop expecting it to print a nice 1 2 3 4 5 6 7 8 9 but it doesn't print anything, instead it assigns that value to i. What's going on? I feel like a failure

bump

I don't even understand what you have written dude. Why are you calling i at the end.

That's a good point. What up with that?

You know that in many programming languages you start counting from 0?

primes = [2, 3, 5, 7]
for prime in primes:
print(prime)

The loop was my try to print the following
"1 2 3 ... 9 ". I made use of end=" " so it print everything in a single line. After it run the loop, nothing is printed but , somehoe, i ends with the string "1 2 3... 9 " being assigned to it. I called i at the end to show it's value has been changed to that string. How could this happen? I just want to print 1 2 3 ffs

this is the code you want:

for i in range(1,10):
print(i)

if you want all the numbers to print on a single line, then do this:

numbers = ''
for i in range(1,10):
numbers += str(i) + ' '
print(numbers)

This, but not entirely.

Here's a working version of OP's code that does exactly what he wanted:

for i in range (1, 11):
print (i, end=" ")

yeah good call. range is exclusive on the upper end though. so if he wants it to print the numbers 1 through 9 then that second parameter should be 10 not 11

Oh shit son, for some reason I was thinking he wanted 1 to 10. Guess I got confused by the fact that in the image I saw two 9's, and was naturally expecting he wanted 9 10....

You're right though. Either works given his intention, just gotta adjust that 11 to a 10 if he wants 1 - 9, or keep it at 11 if he wants 1 - 10.

Additionally, my interpreter's being a tad gay itself, but I'm not sure what the fuck went wrong with OP's. See how his never dropped the numbers naturally, and acted like a non-returned variable?

Please note that I'm doing it on the Python console, so everything on the run.
I'm more concerned about printing it in a single line.

Use a compiled language like a white man.

Yeah what the fuck is up with your shit man.

Maybe recompile/ reinstall the software for python.

D-Did you try turning it off and on again?

What does "python3 --version" tell you? Also, what platform are you running on?

It's because you are a failure user. You can't even post in the right board.

While I'm not that familiar with Python, I notice that there isn't a space between the comma and the end=" " parameter. Could this have an effect?

Appreciate the insight anyway, but no friend, it shouldn't hinder it. And those of us with a working version are able to run that with the exact same expected result.

Fair enough. I'm a C++ jockey, so wasn't sure on the whitespace issue.

Python 3.6.1 (v3.6.1:69c0db5)
Running with PyCharm
Other boards are super slow

Welp, guess my pc is autistic

Sometimes shit just fucks up, my nigga.

I got a program I'm recompiling right now because it spat out errors regarding certain shared object libraries. Although they are all exactly where and how they are supposed to be. Seems it's a bug, due to versioning issues. Reinstalling it should do the trick.

>Running with PyCharm
>PyCharm

Think I just spotted your issue, mate.

Yeah, I just used the standard console and worked fine. What do you guys recommend me to replace the PyTrash?

For starters, I don't think you should be using an IDE, period. Though that is my opinion, and not one everyone shares.

Why not just use vim for writing code, and the stock interpreter for quick testing and prototyping like you're doing now?

Thanks mate, I appreciate your help.

Yer welcome friend.

Filehandle flushing is fucking with you in Pycharm.

primes=[2,3,5,7]
for i in primes:
print(i, end = ' ', flush=True)

You don't need the flush on the command line, but if you're running through PyCharm, the filehandle needs to be flushed.

Basically, the for loop puts everything in stdout, but since there's no newline printed out, the stdout filehandle isn't getting flushed, which means PyCharm doesn't "see" any stuff to collect & print out to the console screen.

If you turn on filehandle flushing, you explicitly force stdout to be flushed when you print, which makes Pycharm notice the output.

The reason you were seeing the "2 3 5 7 7" output was because the original prints weren't flushed, but the final "print(i)" put the newline after it, and caused the filehandle to flush, which then makes it look like all the shit appeared on a single line.

As noted...
> PyCharm
> problem

IDEs are nice time-savers, but when in doubt, drop to your command line and validate the behavior there. If behavior is inconsistent between command line & ide, it's an issue with the IDE.

IDEs have their place. They can speed up refactoring and coding by a huge amount. Vim is good for quick hits, but if you're coding a large-ish project, an IDE used properly is going to speed you up quite a bit.

But for the love of god, avoid that fucking abomination named Eclipse.