学习python笔记:8,随机数
内置随机数函数
import random for i in range(3): print(random.random()) print(random.randint(1,20)) import random members = ['john', 'mary', 'bob', 'mosh'] for i in range(3): print(random.choice(members))
#掷骰子游戏 import random class Dice: def roll(self): first_try = random.randint(1,6) second_try = random.randint(1,6) return(first_try,second_try) dice = Dice() print(dice.roll())