我是一支君子兰,离开生我养我的土壤,就会慢慢枯萎!

发布新日志

  • python 3.2 调用随机函数生成10个数,冒泡排序

    2011-08-12 10:42:16

    下面这个脚本只是学习并练习用的,请不要“鸡蛋里挑骨头”,呵呵

    import random

    print("randrange:append ten numbers from 0 to 100 to list1 array:")
    list1 = []
    for i in range(11):
        a = random.randrange(0,100)
        list1.append(a)

    for i in range(11):
        print("list1[%d] = %3d" % (i,list1[i]))

    print("randint:append ten numbers from 101 to 200 to list2 array:")
    list2 = []
    for i in range(11):
        b = random.randint(101,200)
        list2.append(b)

    for i in range(11):
        print("list2[%d] = %4d" % (i,list2[i]))

    print("uniform.:append ten numbers from 201 to 300 to list array:")
    list3 = []
    for i in range(11):
        c = random.uniform(201,300)
        list3.append(c)

    for i in range(11):
        print("list3[%d] = %10.4f" % (i,list3[i]))

    print("random:append ten numbers from () to list array:")
    list4 = []
    for i in range(11):
        d = random.random()
        list4.append(d)

    for i in range(11):
        print("list4[%d] = %20.18f" % (i,list4[i]))

    print("choice:append ten numbers from list1 to list array:")
    list5 = []
    for i in range(11):
        c = random.choice(list1)
        list5.append(c)

    for i in range(11):
        print("list5[%d] = %3d" % (i,list5[i]))

    for i in range(11):
        for j in range(11):
            if list1[i] < list1[j]:
                list1[i],list1[j] = list1[j],list1[i]

            if list2[i] < list2[j]:
                list2[i],list2[j] = list2[j],list2[i]

            if list3[i] < list3[j]:
                list3[i],list3[j] = list3[j],list3[i]

            if list4[i] < list4[j]:
                list4[i],list4[j] = list4[j],list4[i]

            if list5[i] < list5[j]:
                list5[i],list5[j] = list5[j],list5[i]

    for i in range(11):
        print("list1[%d] = %3d" % (i,list1[i]))

    for i in range(11):
        print("list2[%d] = %4d" % (i,list2[i]))

    for i in range(11):
        print("list3[%d] = %10.4f" % (i,list3[i]))

    for i in range(11):
        print("list4[%d] = %20.18f" % (i,list4[i]))

    for i in range(11):
        print("list5[%d] = %3d" % (i,list5[i]))

    print("done5")

  • Python 3.2版本下实现简单的个人理财计算器(存款)脚本

    2011-08-09 18:35:38

    最近看着物价飞涨,才想起来有好多的天没查看财务状态了,正好公司在进行python 3.2脚本调研,就用这个机会,动手写了一个个人理财计算器。不是很好,但放个这里做纪念,日后改进。O(∩_∩)O~

    print ("Welcome to Financing System")

    Amounte = 0.0                          # 本金初始化

    DepositCurrent = 0.005                 # 活期利率

    TypeDeposit = input("choice the kinds of deposit, current deposit is 1, fixed deposit is 2 and lump deposit is 3") # 获取存款类型
    TypeDeposit = int(TypeDeposit)

    if (TypeDeposit != 1) and (TypeDeposit != 2) and (TypeDeposit != 3):
        print("the kind of deposit is error, it's over")
    elif TypeDeposit == 1 :
        Amounte = input("Enter the number of money, please:")                       # 录入存款金额
        Amounte = int(Amounte)
        Amounte = Amounte * (1 + DepositCurrent)                                    # 计算本金和利息
        print("you choice current deposit and the Effective Annual Rate is %f. One year later, you will get %10.2f" % (DepositCurrent,Amounte))

    elif TypeDeposit == 2 :
        Amounte = input("Enter the number of money, please:")                       # 录入存款金额
        Amounte = int(Amounte)
        RateFixed = input("Enter the Effective Annual Rate(0.0000), please:")
        RateFixed = float (RateFixed)
        Depositmonth = input("how long(months):")
        Depositmonth = int(Depositmonth)
        Amounte += Amounte * RateFixed / 12 * Depositmonth
        print("you choice fixed deposit and the rate is %6.4f. %4d months later, you will get %10.2f" % (RateFixed,Depositmonth,Amounte))

    else :
        NumTerminally = input("Enter the number of money for terminallly:")
        NumTerminally = int(NumTerminally)
        Month = input("How long time for you (month)")
        Month = int(Month)
        RateFixed = input("Enter the Effective Annual Rate(0.0000), please:")
        RateFixed = float (RateFixed)
        TempTerminally = NumTerminally * RateFixed / 12
        TempSum = 0.0
        for i in range(1,Month + 1) :
           TempSum += TempTerminally * i
       
        NumTerminally = TempSum + NumTerminally * Month
        print("you choice lump deposit and the Effective Annual Rate is %6.4f. Three years later, you will get %10.2f" % (RateFixed,NumTerminally))
       
    print("done")

     

     

Open Toolbar