双色球机选投注
双色球玩法规则:
玩法说明:双色球投注区分为红球号码区和蓝球号码区,红球号码范围为 01~33,蓝球号码范围为 01~16。双色球每期从 33 个红球中开出 6 个号码, 从 16 个蓝球中开出 1 个号码作为中奖号码,双色球玩法即是竞猜开奖号码的 6 个红球号码和 1 个蓝球号码,顺序不限。

代码实现:指定蓝球号码,随机多注号码

import random
print("*****福彩双色球*****")
print("====================")
red=[str(i).zfill(2) for i in (random.sample(range(1,31),6))]
print(','.join(red)+","+str(random.choice(range(1,16))).zfill(2))
import random
print("*****福彩双色球*****")
print("====================")
luck=input("请输入您的幸运数字(1~16):\n")
inputx=int(input("请输入双色球彩票组数:\n"))
for i in range(inputx):
    red=[str(i).zfill(2) for i in (random.sample(range(1,31),6))]
    print(','.join(red)+","+luck.zfill(2))

代码运行截图:
在这里插入图片描述

网红小游戏:挑战10秒
挑战10秒游戏规则:按下启动键开始计时,找准时机再次按启动键停止,数字停滞在10秒即挑战成功。
在这里插入图片描述

from tkinter import *
from tkinter.messagebox import *
import time
import random
root=Tk()
rans=[0.1,0.08,0.06,0.04]
count=0
start=False
def ten():                                           # 游戏主题函数
    global start                                    # 定义全局变量start,记录游戏状态
    global count                                     # 定义全局变量count,记录秒数
    num=random.choice(rans)                         # 随机产生间隔时间,增加游戏难度
    fight['text']='停止'                            
    if not start:                                    # 如果是停止状态
        start=True
        while start:
            time.sleep(num)
            count+=0.2
            show['text']=format(count,'.1f')
            show.update()                             
        if show['text']==str(10.0):                # 如果等于10秒,即挑战成功
            warn=showwarning(title='挑战10秒', message='挑战成功,您消费可全部免单!')
        else:
            warn=showwarning(title='挑战10秒', message='挑战失败,可以领取代金券一张!')
    else:
        start=False
        fight['text']='继续挑战'
        count=0
root.title('挑战10秒')                                        #  设置窗体标题
root.wm_attributes('-topmost', 1)                            #  设置窗体置顶
root.geometry('300x120')                                       #  设置窗体大小
root.resizable(width=False, height=False)                   #  设置窗体尺寸不可改变
topic = Label(root, text='挑战10秒')                        #  设置窗体中游戏标题
topic.pack()
show=Label(root,text=str(count))
show.pack()
fight=Button(root,text='开始挑战',command=ten)
fight.pack()
mainloop()

代码运行截图:
在这里插入图片描述

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐