前言

之前做了py学习之路第一期,都是一些没啥实战作用的程序。

学python这么久了,应该更加贴近生活,做一些有用的小程序。

抱歉哈,由于我自律能力不够,寒假没有怎么学UI框架的制作,所以这次仍然是dos版本。

1.原神圣遗物刷取强化模拟(不完整)

可以刷取和强化你的圣遗物!

我只写了大词条,小词条可以忽略不计,所以我没写。

圣遗物强化有4个档位,因为我懒,所以默认按照最大值。

代码如下:

import random
from time import sleep
from os import system
flag=1
list=["暴击率","大生命值","大攻击力","元素充能","大防御力","暴击伤害","元素精通"]
list2=["暴击率","大生命值","大攻击力","元素充能","大防御力","暴击伤害","元素精通"]
dic={"暴击率":3.9,"大生命值":5.8,"大攻击力":5.8,"元素充能":6.5,"大防御力":7.3,"暴击伤害":7.8,"元素精通":11}
while True:
    while flag==1:
        system("cls")
        item_list = ["main", "1", "2", "3", "4"]
        item_value = [0, 0, 0, 0]
        input("回车刷取圣遗物:")
        item_list[0]=random.choice(list)
        random.shuffle(list2)
        item_list[1]=list2[0]
        item_value[0]+=dic[item_list[1]]
        item_list[2] = list2[1]
        item_value[1] += dic[item_list[2]]
        item_list[3] = list2[2]
        item_value[2] += dic[item_list[3]]
        item_list[4] = list2[3]
        item_value[3] += dic[item_list[4]]
        while item_list[0] == item_list[1] or item_list[0] == item_list[2] or item_list[0] == item_list[3] or item_list[0] == item_list[4]:
            item_list = ["main", "1", "2", "3", "4"]
            item_value = [0, 0, 0, 0]
            item_list[0] = random.choice(list)
            random.shuffle(list2)
            item_list[1] = list2[0]
            item_value[0] += dic[item_list[1]]
            item_list[2] = list2[1]
            item_value[1] += dic[item_list[2]]
            item_list[3] = list2[2]
            item_value[2] += dic[item_list[3]]
            item_list[4] = list2[3]
            item_value[3] += dic[item_list[4]]
        print("主词条:"+str(item_list[0]))
        sleep(0.1)
        print("副词条:"+str(item_list[1]),item_value[0],"%")
        sleep(0.1)
        print(item_list[2],item_value[1],"%")
        sleep(0.1)
        print(item_list[3],item_value[2],"%")
        sleep(0.1)
        print(item_list[4],item_value[3],"%")
        sleep(0.1)
        yes_or_not=input("输入Y开始强化,输入N重新生成:")
        if yes_or_not=="Y":
            break
        else:
            flag=1
    for i in range(1,6):
        input("回车强化+4:")
        system("cls")
        sleep(1)
        temp_random=random.randint(0,3)
        item_value[temp_random]+=dic[item_list[temp_random+1]]
        print(item_list[temp_random+1]+"提高到"+str(item_value[temp_random])+"%")
        print("主词条:" + str(item_list[0]))
        print("副词条:" + str(item_list[1]), item_value[0], "%")
        print(item_list[2], item_value[1], "%")
        print(item_list[3], item_value[2], "%")
        print(item_list[4], item_value[3], "%")
    input("强化完成,回车继续:")

2.原神抽卡模拟器

注意:并不是很完整!73发增加概率并没有写!本来写进去的东西也注释掉了,不知道为啥就是行不通。其他没问题。

import random
import os
from time import sleep
print("注意:出金概率为0.06%,歪的概率为50%,本模拟器严格执行这个概率,并且拥有大保底")
flag=0 ##设立循环阈值
##初始化
coin=0
charge_flag=0
wish_flag=0
time=1
wai=0
baodi_num=1
nonup_baodinum=1
armup_baodinum=1
cost=0
aim=0
aim_at=0
character_list=[]
four_star_list=[]
arms_list=[]
while flag==0: ##进入循环
    mode=input("[1]充值 [2]查看账户情况 [3]开抽UP池 [4]开抽常驻池 [5]开抽武器池(还在测试 没写完)")
    if mode=="1":
        charge_flag=0
        while charge_flag==0: ##充值循环
            os.system("cls")
            print("当前账户余额"+str(coin))
            print("[1]128元 相当于1280原石")
            print("[2]328元 相当于3280原石")
            print("[3]648元 送1000原石 相当于7480原石")
            print("[4]氪佬专用 6480元 送5000原石 相当于69800原石")
            charge=input("请问你要充值哪一档[输入5退出]:")
            if charge=="1":
                coin+=1280
                cost+=128
                print("原石余额:" + str(coin))
            elif charge=='2':
                coin+=3280
                cost+=328
                print("原石余额:" + str(coin))
            elif charge=="3":
                coin+=7480
                cost+=648
                print("原石余额:" + str(coin))
            elif charge=="4":
                coin+=69800
                cost+=6480
                print("原石余额:" + str(coin))
            else:
                charge_flag=1 ##退出循环
                wish_flag=0
    elif mode=="2":
        os.system("cls")
        print("花费的钱:"+str(cost))
        print("原石余额:"+str(coin))
        print(str(character_list))
    elif mode=="3":
        os.system("cls")
        wish_flag=0
        print("原石余额:" + str(coin))
        gold_num=[]
        gold_num.append(random.randint(0,1000)) ##生成金数字
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        print("金数字"+str(gold_num))
        up_list=[]
        temp_count=0
        while temp_count<25:
            four_star_list.append(random.randint(0,1000))
            temp_count+=1
        print("紫数字" + str(four_star_list))
        temp_count=0
        while temp_count<50:
            up_list.append(random.randint(1,100))
            temp_count+=1
        wai_dic={1:"[五星]刻晴",2:"[五星]琴",3:"[五星]七七",4:"[五星]迪卢克",5:"[五星]莫娜"}
        four_star_dic={1:"[四星]砂糖",2:"[四星]芭芭拉",3:"[四星]菲谢尔",4:"[四星]班尼特",5:"[四星]雷泽",6:"[四星]凯亚",7:"[四星]安柏",8:"[四星]诺艾尔",9:"[四星]丽莎",10:"[四星]行秋",11:"[四星]北斗",12:"[四星]重云",13:"[四星]香菱",14:"[四星]凝光"}
        while wish_flag==0:##进入抽卡循环
            print("原石余额:"+str(coin))
            wish=input("回车抽单抽,输入10抽10抽,输入1退出:")
            os.system("cls")
            if wish=="10":
                temp_count=0
                while temp_count<10 and wish_flag==0:
                    create_num=random.randint(0,1000) ##生成随机数
                    temp_count+=1
                    if coin<160:
                        print("余额不足请充钱")
                        wish_flag=1
                    else:
                        coin-=160
                        '''''''''
                        if baodi_num<75:
                            gold_num = []
                            gold_num.append(random.randint(0, 1000))  ##生成金数字
                            gold_num.append(random.randint(0, 1000))
                            gold_num.append(random.randint(0, 1000))
                            gold_num.append(random.randint(0, 1000))
                            gold_num.append(random.randint(0, 1000))
                            gold_num.append(random.randint(0, 1000))
                        if baodi_num==75:
                            count=0
                            while count<194:
                                gold_num.append(random.randint(0,1000))
                                count+=1
                        '''''
                        if (create_num in gold_num) or baodi_num==90: ##确认为90保底或者随机数在金列表内
                            if wai==1: ##如果上一次歪了,这一次就不歪了,也就是判断是否大保底
                                character_list.append("[五星]神里凌华")
                                print("你获得[五星]神里凌华"+str(time)+str(baodi_num))
                                baodi_num=1
                            else:
                                temp_num=random.randint(1,100)
                                if temp_num in up_list: ##小保底没歪
                                    character_list.append("[五星]神里凌华")
                                    print("你获得[五星]神里凌华"+str(time)+"   "+str(baodi_num))
                                    baodi_num=1
                                elif not temp_num in up_list: ##歪了,下面开始判断歪哪个
                                    temp_num=random.randint(1,5)
                                    character_list.append(wai_dic[temp_num])
                                    print("你获得"+str(wai_dic[temp_num])+str(time)+"   "+str(baodi_num))
                                    wai=1
                                    baodi_num=1
                        elif time%10==0 and not time==1: ##每十连必出4星
                            temp_num=random.randint(1,14)
                            '''''''''
                            character_list.append(four_star_dic[temp_num])
                            '''
                            print("你获得" + str(four_star_dic[temp_num])+str(time)+"   "+str(baodi_num))
                        elif create_num in four_star_list:##概率出四星
                            temp_num = random.randint(1, 14)
                            '''''''''
                            character_list.append(four_star_dic[temp_num])
                            '''
                            print("你获得" + str(four_star_dic[temp_num])+str(time)+"   "+str(baodi_num))
                        else:
                            print("三星"+str(time)+"   "+str(baodi_num))
                        time+=1
                        baodi_num+=1
            elif wish=="1":
                wish_flag=1
    elif mode=="4":
        os.system("cls")
        wish_flag=0
        print("原石余额:" + str(coin))
        gold_num=[]
        gold_num.append(random.randint(0,1000)) ##生成金数字
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        print("金数字"+str(gold_num))
        up_list=[]
        temp_count=0
        while temp_count<25:
            four_star_list.append(random.randint(0,1000))
            temp_count+=1
        print("紫数字" + str(four_star_list))
        temp_count=0
        while temp_count<50:
            up_list.append(random.randint(1,100))
            temp_count+=1
        wai_dic={1:"[五星]刻晴",2:"[五星]琴",3:"[五星]七七",4:"[五星]迪卢克",5:"[五星]莫娜"}
        four_star_dic={1:"[四星]砂糖",2:"[四星]芭芭拉",3:"[四星]菲谢尔",4:"[四星]班尼特",5:"[四星]雷泽",6:"[四星]凯亚",7:"[四星]安柏",8:"[四星]诺艾尔",9:"[四星]丽莎",10:"[四星]行秋",11:"[四星]北斗",12:"[四星]重云",13:"[四星]香菱",14:"[四星]凝光"}
        while wish_flag==0:##进入抽卡循环
            print("原石余额:"+str(coin))
            wish=input("回车抽单抽,输入10抽10抽,输入1退出:")
            os.system("cls")
            if wish=="10":
                temp_count=0
                while temp_count<10 and wish_flag==0:
                    create_num=random.randint(0,1000) ##生成随机数
                    temp_count+=1
                    if coin<160:
                        print("余额不足请充钱")
                        wish_flag=1
                    else:
                        coin-=160
                        if (create_num in gold_num) or nonup_baodinum==90: ##确认为90保底或者随机数在金列表内
                                temp_num = random.randint(1, 5)
                                character_list.append(wai_dic[temp_num])
                                print("你获得" + str(wai_dic[temp_num]) + str(time) + "   " + str(nonup_baodinum))
                                nonup_baodinum = 1
                        elif time%10==0 and not time==1: ##每十连必出4星
                            temp_num=random.randint(1,14)
                            print("你获得" + str(four_star_dic[temp_num])+str(time)+"   "+str(nonup_baodinum))
                        elif create_num in four_star_list:##概率出四星
                            temp_num = random.randint(1, 14)
                            print("你获得" + str(four_star_dic[temp_num])+str(time)+"   "+str(nonup_baodinum))
                        else:
                            print("三星"+str(time)+"   "+str(nonup_baodinum))
                        time+=1
                        nonup_baodinum+=1
            elif wish=="1":
                wish_flag=1
    elif mode=="5":
        os.system("cls")
        wish_flag=0
        print("原石余额:" + str(coin))
        gold_num=[]
        gold_num.append(random.randint(0,1000)) ##生成金数字
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        gold_num.append(random.randint(0, 1000))
        print("金数字"+str(gold_num))
        up_list=[]
        temp_count=0
        while temp_count<25:
            four_star_list.append(random.randint(0,1000))
            temp_count+=1
        print("紫数字" + str(four_star_list))
        temp_count=0
        while temp_count<50:
            up_list.append(random.randint(1,100))
            temp_count+=1
        up_dic={1:"[五星]雾切之回光",2:"[五星]狼的穷途末路"}
        wai_dic={1:"[五星]阿莫斯之弓",2:"[五星]天空之翼",3:"[五星]四风原典",4:"[五星]天空之卷",5:"[五星]和璞鸢",6:"[五星]天空之脊",7:"[五星]天空之傲",8:"[五星]风鹰剑",9:"[五星]天空之刃"}
        four_star_dic={1:"[四星]砂糖",2:"[四星]芭芭拉",3:"[四星]菲谢尔",4:"[四星]班尼特",5:"[四星]雷泽",6:"[四星]凯亚",7:"[四星]安柏",8:"[四星]诺艾尔",9:"[四星]丽莎",10:"[四星]行秋",11:"[四星]北斗",12:"[四星]重云",13:"[四星]香菱",14:"[四星]凝光"}
        while wish_flag==0:##进入抽卡循环
            print("原石余额:"+str(coin))
            wish=input("回车抽单抽,输入10抽10抽,输入2定轨,输入1退出:")
            os.system("cls")
            if wish=="2":
                aim_at=input("定轨:[1]雾切之回光 [2]狼的穷途末路")
            elif wish=="10":
                temp_count=0
                while temp_count<10 and wish_flag==0:
                    create_num=random.randint(0,1000) ##生成随机数
                    temp_count+=1
                    if coin<160:
                        print("余额不足请充钱")
                        wish_flag=1
                    else:
                        coin-=160
                        if (create_num in gold_num) or armup_baodinum==90: ##确认为90保底或者随机数在金列表内
                            if aim==2: ##如果上一次歪了,这一次就不歪了,也就是判断是否大保底
                                if aim_at=="1":
                                    arms_list.append("[五星]雾切之回光")
                                    print("你获得[五星]雾切之回光"+str(time)+str(armup_baodinum))
                                    aim=0
                                elif aim_at=="2":
                                    arms_list.append("[五星]狼的穷途末路")
                                    print("你获得[五星]狼的穷途末路" + str(time) + str(armup_baodinum))
                            else:
                                temp_num=random.randint(1,100)
                                if temp_num in up_list: ##小保底没歪
                                    if aim_at == "1":
                                        arms_list.append("[五星]雾切之回光")
                                        print("你获得[五星]雾切之回光" + str(time) + str(armup_baodinum))
                                        aim = 0
                                    elif aim_at == "2":
                                        arms_list.append("[五星]狼的穷途末路")
                                    elif not temp_num in up_list: ##歪了,下面开始判断歪哪个
                                        temp_num=random.randint(1,9)
                                        character_list.append(wai_dic[temp_num])
                                        print("你获得"+str(wai_dic[temp_num])+str(time)+"   "+str(armup_baodinum))
                                        wai=1
                                        baodi_num=1
                        elif time%10==0 and not time==1: ##每十连必出4星
                            temp_num=random.randint(1,14)
                            print("你获得" + str(four_star_dic[temp_num])+str(time)+"   "+str(armup_baodinum))
                        elif create_num in four_star_list:##概率出四星
                            temp_num = random.randint(1, 14)
                            print("你获得" + str(four_star_dic[temp_num])+str(time)+"   "+str(armup_baodinum))
                        else:
                            print("三星"+str(time)+"   "+str(armup_baodinum))
                        time+=1
                        armup_baodinum+=1
            elif wish=="1":
                wish_flag=1

3.小学生题目(挺有意思的)

题目:有甲乙丙等共6人,排排队,最左边只能是甲或者乙,最右边不能是甲,问有几种可能?

题目是很简单,只要用itertools把所有的排列可能都列出来,然后遍历一遍判断条件就行了。

虽然简单,但是用python解题的感觉是真的截然不同。

import itertools
people=[1,2,3,4,5,6]
count=0
tlist=[]
tlist_=itertools.permutations(people)
for res in tlist_:
    tlist.append(list(res))
for i in range(0,len(tlist)):
    if (tlist[i][0]==1 or tlist[i][0]==2) and tlist[i][5]!=1:
        print(tlist[i])
        count+=1
print(count)

这一期暂时就这么多,如果还有也只能放下一期了。

以上代码均可直接复制运行,因为无任何文件的引用(python版本:3.9)

最后修改:2022 年 08 月 12 日
如果觉得我的文章对你有用,请随意赞赏