• Python语言程序设计基础(3)—— 基本数据类型


    天天向上

    dayup,dayfactor = 1.0,0.01
    
    for i in range(365):
        if i % 7 in [6,0]:
            dayup = dayup*(1-dayfactor)
        else:
            dayup = dayup*(1+dayfactor)
    print("{:.2f}".format(dayup))

    天天向上2

    def dayUP(df):
        dayup = 1.0
        for i in range(365):
            if i % 7 in [6,0]:
                dayup = dayup*(1-0.01)
            else :
                dayup = dayup*(1+df)
        return dayup
    
    dayfactor = 0.01
    while dayUP(dayfactor) < 37.78:
        dayfactor+=0.01
    print("{:.3f}".format(dayfactor))

    获取星期字符串

    weekstr = "星期一星期二星期三星期四星期五星期六星期日"
    
    weekid = eval(input(""))
    pos = (weekid-1)*3
    print(weekstr[pos:pos+3])

    凯撒密码

    text = input()
    
    for i in range(len(text)):
        if text[i] >= 'a' and text[i] <='z':
            print(chr(ord('a')+(ord(text[i])-ord('a')+3)%26),end='')
        else :
            print(text[i],end="")

    文本精度条

    import time
    print("-------执行开始--------")
    scale = 10
    for i in range(scale+1):
        a = '**'*i
        b = '..'*(scale-i)
        c = (i/scale)*100
        print("%{:^3.0f}[{}->{}]".format(c,a,b))
        time.sleep(0.1)
    print("-------执行结束--------")

    单行刷新

    import time
    scale = 50
    print("执行开始".center(scale,'-'))
    t = time.clock()
    
    for i in range(scale+1):
        a = '*'*i
        b = '.'*(scale-i)
        c = (i/scale)*100
        t-=time.clock()
        print("
    {:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,-t),
              end='')
        time.sleep(0.05)
    print("
    "+"执行结束".center(scale,'-'))

    习题部分

    回文
    a = input()
    
    flag = True
    for i in range(len(a)//2):
        if a[i]!=a[len(a)-i-1]:
            flag = False
            break
        else:
            continue
    if flag:
        print("YES")
    else:
        print("NO")

  • 相关阅读:
    Tomcat 之 Aio的安装步骤
    redis的安装问题
    Tomcat开机自启
    常用基本SQL语句
    点击开启此虚拟机时,出现“该虚拟机似乎正在使用中”问题
    sql表连接left join,right join,inner join三者之间的区别
    Lua 中 ipairs 与 pairs 的区别
    Lua 栈【转】【学习笔记】
    Nodejs 环境设置
    nodejs取得当前执行路径
  • 原文地址:https://www.cnblogs.com/TreeDream/p/9809141.html
Copyright © 2020-2023  润新知