Python123: 基本数据类型 (第3周)

1、实例3:天天向上的力量

def dayUP(df):
dayup=1
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.001
print(“工作日的努力参数是:{:.3f}”.format(dayfactor))

2、实例4:文本进度条

import time
for i in range(101):
print("\r{:3}%".format(i),end="")
time.sleep(0.1)

3、三次方格式化

a=eval(input())
print("{:-^20}".format(pow(a,3)))

4、星号三角形

a=eval(input())
for i in range(1,a+1,2):
print("{0:^{1}}".format(’*’*i, a))

5、恺撒密码

s = input()
t = “”
for c in s:
if ‘a’ <= c <= ‘z’:
t += chr( ord(‘a’) + ((ord©-ord(‘a’)) + 3 )%26 )
elif ‘A’<=c<=‘Z’:
t += chr( ord(‘A’) + ((ord©-ord(‘A’)) + 3 )%26 )
else:
t += c
print(t)

你可能感兴趣的:(Python基础)