+ 1

Basic function for dice simulator doesn't work, unsure why

import random def dice_roll (): x = int (input ("How many sides would you like the die to have? ")) y = int (input ("How many would you like to roll? ")) z = int (input ("Is there a modifier you would like applied? ")) if x != int: dice_roll () if y != int: dice_roll () if z != int: dice_roll () print (random.randint (1,x) * y + z) dice_roll()

14th Oct 2016, 5:17 PM
Chromatick
Chromatick - avatar
3 Réponses
+ 3
I guess your "if" statements are trying to check types for x, y and z. If so, it should be if type(x) != int Doing that also for y and z should work.
14th Oct 2016, 6:13 PM
John Otu
John Otu - avatar
+ 2
separate note, but statistically this is wrong. the odds of rolling 3 d6 and getting 18 aren't the same as rolling 3 d6 and getting 9. you should use a for loop to roll new dice instead of assuming all of them are the same. the more dice the closer to average your results should be
14th Oct 2016, 7:21 PM
Justin Golden
Justin Golden - avatar
+ 1
ahh, thank you, I knew for a fact that was the issue , but I didn't know how to properly check for a TYPE of data, I just assumed this would work. thank you!
14th Oct 2016, 6:17 PM
Chromatick
Chromatick - avatar