Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> from random import randrange >>> randrange(1, 101) 99 >>> randrange(1, 101) 71 >>> randrange(1, 101) 67 >>> randrange(1, 101) 59 >>> from random import random >>> random() 0.14257189975428808 >>> random() 0.6288419512719052 >>> random() 0.1809694149882931 >>> random() 0.5291575420260192 >>> random() 0.6733136195100066 >>> randrange(1, 7) 3 >>> randrange(1, 7) 6 >>> randrange(1, 7) 4 >>> randrange(1, 7) 1 >>> def twodice(): first = randrange(1, 7) second = randrange(1, 7) return a, b >>> def twodice(): first = randrange(1, 7) second = randrange(1, 7) return first, second >>> twodice() (5, 3) >>> twodice() (3, 2) >>> twodice() (5, 5) >>> twodice() (4, 5) >>> twodice() (6, 4) >>> twodice() (5, 4) >>> def suit(): suits = ["Clubs", "Diamonds", "Hearts", "Spades"] return(suits[randrange(0, 4)]) >>> suit() 'Spades' >>> suit() 'Hearts' >>> suit() 'Diamonds' >>> suit() 'Diamonds' >>> suit() 'Diamonds' >>> suit() 'Spades' >>> suit() 'Spades' >>> random() < .2 False >>> random()< .2 True >>> random()< .2 False >>> random()< .2 False >>> random()< .2 False >>> random()< .2 False >>> random()< .2 True >>> random()< .2 True >>> random()< .2 False >>> random()< .2 False >>> random()< .2 False >>> random()< .2 False >>> random()< .2 False >>> random()< .2 False >>> random()< .2 False >>> def probTrue(p): return random() < p >>> probTrue(.75) True >>> probTrue(.75) False >>> probTrue(.75) True >>> probTrue(.75) True >>> probTrue(.75) False >>> probTrue(.75) False >>> probTrue(.75) True >>> probTrue(.75) True >>> probTrue(.75) True >>> probTrue(.75) True >>> probTrue(.75) True >>> probTrue(.75) True >>> probTrue(.75) False >>> probTrue(.75) True >>> probTrue(.75) True >>> probTrue(.75) False >>> winsA = 12 >>> n =50 >>> print("Wins for A: {0}({1:0.1%})".format(winsA, winsA/n)) Wins for A: 12(24.0%) >>>