#函數的舉例python
1 def add(a,b,c,d): 2 e=a+b+c+d 3 #print(e) 4 return e 5 6 res1=add(1,2,3,4) 7 print("本次相加結果:",res1)
#線程舉例ide
1 import treading 2 import time 3 4 def run(name): 5 print(name,"線程執行了") 6 time.sleep(5) 7 8 t1=treading.Tread(target=run,args=("t1",)) 9 t2=treading.Tread(target=run,args=("t2",)) 10 11 t1.start() #啓動線程 12 t2.start() 13 14 print("執行完畢")
#模擬銀行實時存取款(while,connection,break等嵌套使用)函數
1 card1="1001" 2 pwd1="123456" 3 ban1=10000 4 5 card2="1002" 6 pwd2="123456" 7 ban2=10000 8 9 card3="1003" 10 pwd3="123456" 11 ban3=10000 12 13 print("歡迎來到python銀行!") 14 times=1 15 16 while True: 17 card=input("請輸入銀行卡號:") 18 pwd=input("請輸入密碼:") 19 20 ban=0 #餘額 21 22 if card==card1 and pwd==pwd1: 23 ban=ban1 24 elif card==card2 and pwd==pwd2: 25 ban=ban2 26 elif card==card3 and pwd==pwd3: 27 ban=ban3 28 else: 29 times=times+1 30 if times>=3: 31 print("您已經3次輸入錯誤,請聯繫銀行櫃檯") 32 break 33 else: 34 print("卡號密碼輸入錯誤,請從新輸入") 35 continue 36 37 while True: 38 num=input("請輸入要辦理的業務:1.存款 2.取款 3.退卡") 39 if num=="1": 40 inn=float(input("請輸入存款金額:")) 41 if inn<=0: 42 print("存款金額請大於0!") 43 else: 44 ban=ban+inn 45 print("存款成功,存入:",inn,"餘額:",ban) 46 elif num=="2": 47 out=float(input("請輸入取款金額:")) 48 if out>ban: 49 print("餘額不足,趕忙去賺錢!") 50 continue 51 else: 52 ban=ban-out 53 print("取款成功,取出:",out,"餘額:",ban) 54 elif num=="3": 55 print("請收好您的卡片,歡迎下次再來!") 56 break 57 else: 58 print("輸入有誤") 59 continue