【python zip】python 随机数使用方法,推导以及字符串,双色球小程序实例

时间:2021-08-19  来源:python  阅读:

如下所示:

#随机数的使用
import random #导入random
random.randint(0,9)#制定随机数0到9
i=random.sample(range(1,34),6)#输出6个随机数,范围是1到34
i.sort()#排序方法,排序时更改原数组,无返回值
sorted(i)#排序函数,排序时不影响原数组,产生新的排序后数据
print("----------------用上述的随机数做一个双色球---------------------")
sj=random.sample(range(1,34),6)
print(sj,random.randint(1,17))
#if多值判断
n=4
if n in (4,5,6,8):
  print("元组里面有",n,"这个值")
else:
  print("元组里面不存在",n,"这个值")

#利用while循环输出1dao100的和
i=0
he=0
while i<100 :
  he=he+i
  i+=1
print(he)
#list集合使用冒泡排序从大道小排序
li=[9,5,1,8,7,3]
for i in range(0,len(li)):
  for j in range(0,len(li)-i-1):
    if li[j]python","Height","wall","Hight"]
print([s for s in td if s.startswith("H")])

【python zip】python 随机数使用方法,推导以及字符串,双色球小程序实例

http://m.bbyears.com/jiaocheng/136892.html

推荐访问:python基础教程 python3
相关阅读 猜你喜欢
本类排行 本类最新