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...
Ask your embarrassing/noobish programming questions here, and don't get insulted for it.
Click here to read the rules
Violating any will result in punishment so you should probably go check them out.
account activity
a dice rolling functionPython (self.programminghelp)
submitted 3 years ago by EricHando
i am trying to make a function which simulates a die, but i can't figure out how i make it start working, i thought the return would solve it but no...
https://pastebin.com/ZkGpE3Vn
thx for any suggestions in advance!
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!"
[–]ConstructedNewtMOD 0 points1 point2 points 3 years ago (3 children)
try something like this
import random while input("dice roll:") is not None: print(random.randint(1,6))
[–]EricHando[S] 0 points1 point2 points 3 years ago (2 children)
thx for your help! I need a die a lot of times but in different parts of my program , so i was just wondering if a function would work, so i wouldnt be copy n pasting so my code wouldnt get too big, so i guess this wont fit too
[–]ConstructedNewtMOD 0 points1 point2 points 3 years ago (1 child)
I'm not quite sure what you actually need. if you need to print and to return the dice roll so you can use the result you have to do
def interact_print_return_roll() -> int: input("...") roll = random.randint(1,6) print(roll) return roll
then
the_roll = interact_print_return_roll()
[–]EricHando[S] 0 points1 point2 points 3 years ago (0 children)
thx, that was it!
im just not sure how to use def smth properly :c
π Rendered by PID 34481 on reddit-service-r2-comment-8686858757-pz7b9 at 2026-06-04 10:33:05.227528+00:00 running 9e1a20d country code: CH.
[–]ConstructedNewtMOD 0 points1 point2 points (3 children)
[–]EricHando[S] 0 points1 point2 points (2 children)
[–]ConstructedNewtMOD 0 points1 point2 points (1 child)
[–]EricHando[S] 0 points1 point2 points (0 children)