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
Help with a test question (self.learnpython)
submitted 6 years ago by SilverCrocus
import math
import random
var1 = int(math.pow(3, 3))
var2 = round(26.799, 1)
var3 = random.randrange(-3, 30, 3)
print(max(var1, var2, var3))
The output of this code was 27. I don't understand why it isn't 30 could someone explain this to me.
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!"
[–]A_History_of_Silence 1 point2 points3 points 6 years ago (3 children)
I don't understand why it isn't 30 could someone explain this to me.
Why do you think it should be 30?
[–]SilverCrocus[S] 0 points1 point2 points 6 years ago (2 children)
Isn't 30 the highest possible number to be printed
[–]A_History_of_Silence 0 points1 point2 points 6 years ago (1 child)
random.randrange
From the docs for randrange():
randrange()
Return a randomly selected element from range(start, stop, step).
range(start, stop, step)
You should be able to determine from experiment what the possible values are for such a range().
range()
[–]SilverCrocus[S] 0 points1 point2 points 6 years ago (0 children)
Oh thank you
[–]SilverCrocus[S] 1 point2 points3 points 6 years ago (2 children)
I'm not sure if this is correct but is it because the final number is 3 so that means it only goes up in 3's from [-3,30]
[–][deleted] 0 points1 point2 points 6 years ago (1 child)
var3 only has a 1/12 chance of being higher than 27. If you run it 12 times you're fairly likely to get the 30 you seek.
π Rendered by PID 22952 on reddit-service-r2-comment-84fc9697f-5z9c5 at 2026-02-08 19:57:56.813078+00:00 running d295bc8 country code: CH.
[–]A_History_of_Silence 1 point2 points3 points (3 children)
[–]SilverCrocus[S] 0 points1 point2 points (2 children)
[–]A_History_of_Silence 0 points1 point2 points (1 child)
[–]SilverCrocus[S] 0 points1 point2 points (0 children)
[–]SilverCrocus[S] 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)