zoukankan      html  css  js  c++  java
  • 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")

  • 相关阅读:
    Chrome下载无后缀问题
    duilib程序HelloWorld
    go的windows下的安装包
    ASP.NET MVC异步上传图片和富文本编辑器的使用详解
    搭建go环境(windows和linux)
    构建离线Go编程指南——gotour
    判定模块加载时是否存在循环依赖
    Winform开发框架之框架演化
    为什么要写技术博
    JTREE使用例子—创建一个客户端界面
  • 原文地址:https://www.cnblogs.com/TreeDream/p/9809141.html
Copyright © 2011-2022 走看看