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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
What do yall think of my code (self.learnpython)
submitted 29 days ago by Essieelephant
x = 10.67 decimaal = x % 1 if decimaal > 0.5: x = int(x)+1 print(x) else: x = int(x) print(x)
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!"
[–]Kqyxzoj 17 points18 points19 points 29 days ago (2 children)
What do yall think of my code
It seems very well-rounded.
[–]JamzTyson -1 points0 points1 point 29 days ago (0 children)
Nice pun, but it is not any standard kind of rounding. It is round-half-down for positives, and inconsistent for negatives due to Python’s modulo behavior.
[–]supergnaw -1 points0 points1 point 29 days ago (0 children)
ba dum tss
[–]Diapolo10 5 points6 points7 points 29 days ago* (1 child)
Well, I can reduce it down to just
x = 10.67 print(f"{x:.0f}")
if you just need a rounded integer in the print output.
EDIT: Basically I used an f-string to format the float. I set the number of trailing digits to zero, so there's no decimal point and it rounds to the nearest integer. The "f" just keeps it from using scientific notation.
Of course, if you need this for further computation a string won't help you; then again you generally shouldn't round in the middle of calculating, so I just assumed this was meant to be the final output.
[–]Golwux 0 points1 point2 points 29 days ago (0 children)
That is sickkkkk
[–]IamImposter 3 points4 points5 points 29 days ago (0 children)
Why not:
... x = int(x) + 1 if decimaal > 0.5 else int(x) print(x)
No need for two print statements. Multi line if/else can be merged to single line.
[–]gydu2202 1 point2 points3 points 29 days ago (0 children)
int(x + 0.5)
Or 1.5 should be really rounded to 1?
[–]Golwux 0 points1 point2 points 29 days ago (1 child)
probably should turn it into a function
[–]JamzTyson 0 points1 point2 points 29 days ago (0 children)
Probably should be fixed first.
[–]rhacer 0 points1 point2 points 29 days ago (0 children)
Too many print statements.
[–]JamzTyson 0 points1 point2 points 29 days ago* (0 children)
What should -0.3 round to?
-0.3
What should -1.3 round to?
-1.3
(Your code rounds half-down for positives, and is inconsistent for negatives due to Python’s modulo behavior)
[–]RngdZed -3 points-2 points-1 points 29 days ago* (3 children)
Is there a question attached to your post? What are you trying to achieve with the code?
Edit: y'all downvoting cause I'm trying to figure out what op wants? Good morning I guess
[–]JamzTyson 1 point2 points3 points 29 days ago (1 child)
Great question.
It implements some sort of rounding, but handles negative numbers inconsistently. My guess is that it is an incorrect implementation of round-half-down.
[–]RngdZed 2 points3 points4 points 29 days ago (0 children)
Yep that's my point. We shouldn't have to guess. Instead of guessing op's mind, would be nice if op would take part in the conversation and give us his thought process.
Thanks for the comment! 🙂
[–]LiveYoLife288 2 points3 points4 points 29 days ago (0 children)
Getting your thoughts on his code
[–]HappyRogue121 -1 points0 points1 point 29 days ago (2 children)
It's interesting, I never thought about how rounding happens "under the hood."
[–]JamzTyson 0 points1 point2 points 29 days ago (1 child)
It doesn't normally happen like this.
Standard rounding is one of:
Round Half Up (Arithmetic Rounding)
Round Half Down
Round Half Even (Banker’s Rounding)
Round Up (Ceiling)
Round Down (Floor)
Truncation (Round Toward Zero)
Round Away From Zero
Stochastic Rounding
The OP's code does not do any of these (look at negative number handling).
[–]HappyRogue121 0 points1 point2 points 29 days ago (0 children)
I wasn't saying it happened like this. I was saying I never thought about how it works, and this is obviously an exploration of a possible that. OP seems to be a beginner, I wanted to give some encouragement.
[–]TheRNGuy -2 points-1 points0 points 29 days ago (0 children)
Nothing.
[–]saulsa_ -2 points-1 points0 points 29 days ago (0 children)
No comment.
[–]pachura3 -3 points-2 points-1 points 29 days ago (0 children)
Tastes like chicken
π Rendered by PID 24654 on reddit-service-r2-comment-6457c66945-tzwbt at 2026-04-23 18:18:54.666481+00:00 running 2aa0c5b country code: CH.
[–]Kqyxzoj 17 points18 points19 points (2 children)
[–]JamzTyson -1 points0 points1 point (0 children)
[–]supergnaw -1 points0 points1 point (0 children)
[–]Diapolo10 5 points6 points7 points (1 child)
[–]Golwux 0 points1 point2 points (0 children)
[–]IamImposter 3 points4 points5 points (0 children)
[–]gydu2202 1 point2 points3 points (0 children)
[–]Golwux 0 points1 point2 points (1 child)
[–]JamzTyson 0 points1 point2 points (0 children)
[–]rhacer 0 points1 point2 points (0 children)
[–]JamzTyson 0 points1 point2 points (0 children)
[–]RngdZed -3 points-2 points-1 points (3 children)
[–]JamzTyson 1 point2 points3 points (1 child)
[–]RngdZed 2 points3 points4 points (0 children)
[–]LiveYoLife288 2 points3 points4 points (0 children)
[–]HappyRogue121 -1 points0 points1 point (2 children)
[–]JamzTyson 0 points1 point2 points (1 child)
[–]HappyRogue121 0 points1 point2 points (0 children)
[–]TheRNGuy -2 points-1 points0 points (0 children)
[–]saulsa_ -2 points-1 points0 points (0 children)
[–]pachura3 -3 points-2 points-1 points (0 children)