新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:四個(gè)python小練習(xí)
四個(gè)python小練習(xí):

創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司是一家服務(wù)多年做網(wǎng)站建設(shè)策劃設(shè)計(jì)制作的公司,為廣大用戶提供了網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作,成都網(wǎng)站設(shè)計(jì),1元廣告,成都做網(wǎng)站選創(chuàng)新互聯(lián),貼合企業(yè)需求,高性價(jià)比,滿足客戶不同層次的需求一站式服務(wù)歡迎致電。
1、打印出1-100之間的所有偶數(shù)
def even_print(): for i in range(1,101): if i % 2 == 0: print (i) even_print() #列表解析式的方式: k = [n for n in range(1,101) if n%2 == 0] print (k)2、設(shè)計(jì)一個(gè)函數(shù),在桌面上創(chuàng)建10個(gè)文件,并以數(shù)字命名
def text_creation(): path = 'C:/Users/Administrator/Desktop' for name in range (1,11): with open(path + str(name) + '.txt','w') as text: text.write(str(name)) text.close() print ('done')text_creation()3、復(fù)利計(jì)算函數(shù)
def invest(amount,rate,time): print('principal amount:{}'.format(amount)) for t in range(1,time + 1): amount = amount * (1 + rate) print ('year {}: ${}'.format(t,amount)) invest(100,.05,8) invest(2000,.025,5)4、隨機(jī)驗(yàn)證碼
import random checkcode = '' for i in range(4): current = random.randrange(0,4) if current != i: temp = chr(random.randint(65,90)) else: temp = random.randint(0,9) checkcode += str(temp) print (checkcode)
網(wǎng)頁題目:創(chuàng)新互聯(lián)Python教程:四個(gè)python小練習(xí)
當(dāng)前路徑:http://fisionsoft.com.cn/article/ccogjgh.html


咨詢
建站咨詢
