python用random模块模拟抽奖逻辑(print修改end参数使打印结果不分行)

import random   #引入random模块,运用random函数
list_one=["10081","10082","10083","10084","10085"]    #可获得一等奖名单
list_two=["10091","10092","10093","10094","10095","10096","10097","10098"]   #可获得二等奖名单
First_prize=random.sample(list_one,1)    #抽取一名一等奖
Second_prize=random.sample(list_two,3)  #抽取三名二等奖
j=0
print("一等奖名单:",First_prize[0])   #打印一等奖名单
for i in Second_prize:
   if j==0:
     print("二等奖工号:",i,end="");   #用end可使循环结果不分行,默认print的end值为 ,默认分行,end可设置任意参数,循环可以避免打印值之前有多余的的(end的值)
   else:
     print(" ",i,end="");
   j=j+1

红尘往事,一切随风!
原文地址:https://www.cnblogs.com/xwenwu/p/12160445.html