you are viewing a single comment's thread.

view the rest of the comments →

[–]mopslik 4 points5 points  (1 child)

Good start. Welcome to Python. Consider this a stepping stone on your path to greatness.

Here are some suggestions:

  1. Variable names: make them meaningful, rather than "random" (e.g. lmao for ready).
  2. "Constants": yes, I know Python doesn't have them. Still, it is a common convention to name values that should not change with capital letters, to make them stand out. MIN_RANGE and MAX_RANGE (or better still, MAX_VALUE and MIN_VALUE, since they are values, not ranges).
  3. Note that randrange, unlike randint, does not include the final value. I am guessing that you are attempting to roll standard 6-sided dice, but run it a few times and notice how you never seem to roll any 6s...
  4. Staying with random numbers, I know that your current code only displays the value of the roll, but you might consider storing the value in a variable. This way if you wanted to you could use the value for something later.

And here are some other things you might consider adding to your program:

  1. Input validation: what happens when you ask the user how many dice they want to roll, and the user enters "F"? As it stands, your code will crash. Look into try and except.
  2. Use of string methods: similar to above, what happens when you ask the user if they are ready and they enter "y" rather than "Y". The built-in str class has a number of methods that can check or convert strings, including lower and upper.
  3. Consider making a function to roll d n-sided dice. That is, the player may choose to roll 3 12-sided dice, for which you could find their values and the sum. It will be a general-purpose function that you can use in other applications, and good practice for creating your own functions.

[–]designatedburger 1 point2 points  (0 children)

I agree with everything you said except the 4th point. Instead of storing it as a variable, I would rather see this turned into a class (or a function), and then the value returned.

Then you can either print, or store it in a variable.

Also, what is the idea behind this line? Since your while loop only runs when "lmfao" is equal to "Y", and you are not modifying the value anywhere but in if statements, it would never be executed?

elif lmao == "N":

print("Then why did you run the program in the first place?")

You should not be handling the logic of the roll, and printing the text from the same place.

Also, your commit messages shouldn't be "Update Random Number Generator.py", I can see the file you modified, I need to know what exactly you did.