初学python-练习_2使用python编写彩票软件

#!/usr/bin/python
#-*- coding: UTF-8 -*- #指定编码格式,让py文件支持万国码
#设置生成票数的最大值
import sys;
Maximum = sys.maxint;
#设置生成票数的最小值
Minimum = 1000;
#设置生成多少票数
ticket_number = 10;
#生成票
#导入随机数模块
import random;
#定义一个列表,列表大小为票数max
list1 = [0]*ticket_number;
#lack票号
lack_ticket = 0;
#设置多少分钟后开奖
Minute = 5;
#生成随机数
for i in range(ticket_number):
    list1[i] = random.randint(Minimum,Maximum);
    #初票是不会重复的,所以无需检查
    if i == 0:#python不允许空语句,所以随便打印一行print
        print "Don t do any thing";
    else:#检查刚生成的数与已生成的票号是否重复了
        for i_ in range(i):
            if list1[i] == list1[i_]:
                #repeat...
                i = i-1;
                break;
            else:
                print "no repeat.."; 

#选中幸运票号
lack_ticket = random.randint(0,ticket_number);
#打印欢迎界面
print "******************";
for Line in range(4):
    print "*                *";
    if Line == 1:
        print "*  欢迎购买彩票  *";
print "******************";
#将生成的票数打印出来,供用户挑选.
print "\n******************";
print "*共生成了",ticket_number,"张票*";
print "******************";
print "\n******************";
print "*     票号码     *";
print "******************";
#打印票数
#基于linux/unix内核自带颜色表打印红色文字
print "\n\033[31;47m**************************\033[0m";
for i in range(ticket_number):
    print i+1,".",list1[i]; #i subscript is 1
#Linux/unix color table
print "\033[31;47m***************************\033[0m\n";
#判断票号是否正确,错误重新输入
while True:
    ticket_purchase = input("请输入要购买的票号的id编号:");
    if  ticket_purchase > ticket_number:
        print "票号无效";
    else:
        break;
#购买成功...
print "购买成功","\n您购买的票号id编号为:",ticket_purchase,\
        "\n票号为:",list1[ticket_purchase-1];   #subscript is 0
print "票号将在",Minute,"分钟后开奖..请您耐心等待,",\
        "这段时间或许您可以去喝杯咖啡...",;
#由于提示信息没有换行符无法刷新缓冲区立马进入sleep会将提示信息卡在缓冲区里
#在进入sleep前刷新一次缓冲区
sys.stdout.flush();
#导入time模块sleep
import time;
time.sleep(Minute*60);  #秒与分的转换
#开奖
print "开奖时间到啦";
print "本次中奖票号id编号为:",lack_ticket+1,\
        "\n票号为:",list1[lack_ticket];
#看一下是否中奖
if list1[ticket_purchase-1] == list1[lack_ticket]:
    print "恭喜您中奖了";
else:
    print "很遗憾您并没有中奖,再接再厉...";
#end....

 

运行示列:

 

 

Don t do any thing
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
no repeat..
******************
*                *
*                *
*   欢迎购买彩票   *
*                *
*                *
******************

******************
*共生成了 10 张票*
******************

******************
*     票号码      *
******************

**************************
1 . 8644501134800330508
2 . 3887202673607339556
3 . 3598243146269513916
4 . 4983293017054675182
5 . 5279825068692954272
6 . 5228774809957491761
7 . 2965632013227319086
8 . 6810897749549019688
9 . 7214026084612253060
10 . 4189510998270383566
***************************

请输入要购买的票号的id编号:3
购买成功 
您购买的票号id编号为: 3 
票号为: 3598243146269513916
票号将在 5 分钟后开奖..请您耐心等待, 这段时间或许您可以去喝杯咖啡... 开奖时间到啦
本次中奖票号id编号为: 3 
票号为: 3598243146269513916
恭喜您中奖了

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

17岁boy想当攻城狮

感谢打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值