Python語言程序設計基礎(3)—— 基本數據類型

每天向上spa

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))

每天向上2code

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))

 

獲取星期字符串orm

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

 

凱撒密碼blog

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("-------執行結束--------")

 

單行刷新input

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,'-'))

 

習題部分form

迴文
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")
相關文章
相關標籤/搜索