python第三周基本数据类型编程练习

#简单的开始文本进度条
import time
scale = 10
print("------执行开始------")
for i in range(scale+1):
    a =‘*‘ * i
    b =‘.‘*(scale - i)
    c =(i/scale)*100
    print("{:^3.0f}%[{}->{}]".format(c,a,b))
    time.sleep(1)
print("------执行结束------")
#单行动态刷新
import time
for i in range (101):
    print("\r{:3}%".format(i),end="")#默认输出结束后出一个换行即end=“\n”,此处end="" \r指每次输出结束后光标回到本行前端
    time.sleep(0.1)
#完整文本进度条
import time
scale = 50
print("执行开始".center(scale//2,"-"))
start = time.perf_counter()
for i in range(scale+1):
    a =‘*‘ * i
    b =‘.‘*(scale - i)
    c =(i/scale)*100
    dur = time.perf_counter() - start
    print("\r{:^3.0f}%[{}->{}]{:.2f}s".format(c,a,b,dur),end=‘‘)
    time.sleep(0.1)
print("执行结束".center(scale//2,‘-‘))
#同符号数学运算
N = input()
n = abs(eval(N))
a = n
b = abs(n+10)
c = abs(n-10)
d = abs(n*10)
if N[0] in [‘-‘]:
    print("{} {} {} {}".format(a,-b,-c,-d))
else:
    print("{} {} {} {}".format(a,b,c,d))
#天天向上的力量
N = input()
n = eval(N)
oneday = 1
a = pow(1+n/1000,365)
b = pow(1-n/1000,365)
c=a//b
print("{:.2f},{:.2f},{:.0f}".format(a,b,c))
#星号三角形
N = input()
n = int((eval(N)+1)/2)
for i in range(n):
    a = ‘*‘ * (2*(i+1)-1)
    b = ‘ ‘ * (n-i-1)
    print("{}{}{}".format(b,a,b))
#凯撒密码
book = input()
n = len(book)
for i in range(n):
    if book[i] in [‘x‘,‘y‘,‘z‘]:
        print(chr(ord(book[i])-23),end="")
    elif book[i]==" ":
        print(" ",end="")
    else:
        print(chr(ord(book[i])+3),end="")

题目来源:python123.io

相关推荐