将上一篇的简单彩票系统经过封装后
#coding=utf-8
'''
Created on 2020年1月2日
@author: Administrator
'''
import random
from _overlapped import NULL
#买彩票
#账户
account=0
def buyTicketAndPoint():
i=0
#定义全局变量
global ticket
ticket=[]
while 1:
a=input("请输入购买的数字")
if (a=="" or a==NULL):
print('''
输入的数字为空,请重新输入
''')
elif (int(a) >=0 and int(a)<=37):
ticket.append(a)
i+=1
if (i==7):
break
else:
print('''
输入越界,请重新输入
''')
#打印彩票
#把列表m中的元素用,连接 形成新的字符串
global ticket1
#将ticket列表中的字符串转换为int类型
ticket1 = list(map(int, ticket))
ticket1.sort()#排序
print (','.join(ticket))
#开奖
def getTicketAndPrint():
global b
b=[]
for d in range(0,7):
n=random.randint(0,37)
if n not in b:
b.append(n)
#打印开奖
b.sort()
print (','.join('%s'%d for d in b))
#兑奖
def getMoney():
c=[x for x in ticket1 if x in b]#两个列表之间比较相同的数组成的列表
e=len(c)
print ('''有%s个数字相同'''%e)
if e==4:
print('''
恭喜您,获得四等奖
'''
)
elif e==5:
print('''
恭喜您,获得三等奖
'''
)
elif e==6:
print('''
恭喜您,获得二等奖
'''
)
elif e==7:
print('''
恭喜您,获得一等奖
'''
)
else :
print('''
很抱歉,您未中奖
'''
)
buyTicketAndPoint()
getTicketAndPrint()
getMoney()