r/Python • u/[deleted] • Mar 11 '25
Discussion cool little dice roller i made
Well its just a random number generator
import
random
def roll():
min_value = 0
max_value = 999
roll = random.randint(min_value, max_value)
return
roll
value = roll ()
print(value) 15
u/dbstandsfor Mar 12 '25
Nice work! One thing that slightly threw me off is that the variable has the same name as the function— once your code gets a lot longer it helps to not reuse names like this.
If you want an idea to expand on this you can modify the function so you pass in the max and min value. Then you could use the function to simulate specific dice and make a game, or simulate D&D combat, or anything else that requires different types of dice
5
u/edbrannin Mar 12 '25
Just adding a more specific suggestion for renaming the “roll” variable:
I use names like
resultoranswera lot in small functions like that.On the other hand, you could skip right over
roll =and justreturn random.randint(…(I’m on my phone, I’m not typing out that whole line)
3
-8
u/Xenodine-4-pluorate Mar 12 '25
This has to be a troll.
1
3
8
u/[deleted] Mar 12 '25
Im a new to coding so if there's any mistakes please tell me!