I have been working on a simple dice roller. This is what I'm struggling with:
import random
print("What kind of dice would you like to roll?")
class dice:
input("D4, D6, D8, D10, D20, D30, D100?")
print('How many dice should I roll?')
class many:
input("1, 13, 53, etc. ?")
if dice ==('d4' or '4'):
for x in range(many):
print(random.randint(1,4))
print('Again?')
-
I haven't found an answer whether a class will work with the 'range' function, however I do not get any errors in the editor or when running the program.
-
The code itself does prompt for the class input, however the print function for
random.randint
appears to be ignored/skipped over, as it does not print a result, the code goes to the next line and carries on.
This is what I get as output:
What kind of dice would you like to roll?
D4, D6, D8, D10, D20, D30, D100?4
How many dice should I roll?
1, 13, 53, etc. ?1
Again?
I did read through the documentation for the random
library and I could get this example script to run without issue, however when I replace the range in my own script with an integer instead of the class 'many', it still fails to print the result. Ultimately I'd like the range to be set by the user rather than a set amount.
This is the example 'Random' script that runs as it should:
import random
for x in range(10):
print(random.randint(1,101))
81
87
35
20
89
53
13
13
20
95
Aucun commentaire:
Enregistrer un commentaire