def rr(self): #self.rrs=1 i = 0 while i < self.num: if self.dice[i] < self.target: a = rad() * 6 + 1 self.dice[i] = int(a) self.x[i] = int(a) self.consect(1, ix=i) i += 1 self.count(1)
def roll(self): self.dice = [] self.x = [] try: self.num = int(gui.numentry.get()) except Exception: pass i = 0 while i < self.num: a = rad() * 6 + 1 self.dice.append(int(a)) self.x.append(int(a)) i += 1 self.count(0)
#使用任意数量的关键字实参,两个*号表示传递一个字典 def buildProfile(first, last, **userInfo): proFile = {} proFile['first_name'] = first proFile['last_name'] = last for key, value in userInfo.items(): proFile[key] = value return proFile userProfile = buildProfile('王', '三', loc='guangzhou', dep='bumen') print(userProfile) print('*' * 20) #导入模块的时候给模块指定别名 import random as ra print(ra.randint(1, 3)) print('*' * 20) #导入模块中的函数的时候给函数重命名,使用过程中不需要按原来的写模块名.函数名的形式 from random import randint as rad print(rad(1, 3)) print('*' * 20) #导入模块中所有的函数 from random import * print(randint(1, 3)) print('*' * 20)
import random r = random.rad(100.0, 101.5) print(r)