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

时间:2022-08-28 23:37:04

天天向上

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("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,-t),\
          end='')
    time.sleep(0.05)
print("\n"+"执行结束".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")