Python基于面向对象思想模拟彩票系统
import random class Lottery : def __init__ ( self ) : # 用来存储彩票的号码 self . number_list = [ ] # 彩票价格 self . price = 2 def show ( self ) : self . number_list . sort ( ) print ( f '{self.number_list}' ) class System : def __init__ ( self ) : pass # 得到一组包含随机号码的彩票对象 def creat_lottey ( self ) : # 创建一个彩票对象 lottery = Lottery ( ) # 循环生成随机号码 for i in range ( 3 ) : n = random . randint ( 0 , 9 ) # 将生成的号码存储到彩票对象的列表属性中 lottery . number_list . append ( n ) else : lottery . number_list . sort ( ) return lottery # 系统开奖 def run ( self ) : return self . creat_lottey ( ) class Person : def __init__ ( self , name ,