实战01(打印象棋口诀)
1 str1 = '马走日' 2 str2 = ',' 3 str3 = '象走田' 4 str4 = ',' 5 str5 = '车走直线炮翻山' 6 str6 = ',' 7 str7 = '士走斜线护将边' 8 str8 = ',' 9 str9 = '小卒一去不回还' 10 str10 = '.' 11 print("象棋口诀"+':') 12 print(str1 +str2) 13 print(str3 + str4) 14 print(str5 + str6) 15 print(str7 + str8) 16 print(str9 + str10)
实战02(判断车牌归属地)
1 str1 = '津A•12345', '沪A•23456', '京A•34567' 2 for i in range(len(str1)): 3 print('第' + str(i + 1) + '张车牌号码:\n' +str1[i]) 4 if str1[i][0] == '津': 5 print('这张号牌的归属地:天津') 6 if str1[i][0] == '沪': 7 print('这张号牌的归属地:上海') 8 if str1[i][0] == '京': 9 print('这张号牌的归属地:北京')
实战03(模拟微信抢红包)
1 import random 2 import decimal 3 money = input("请输入要装入红包的总金额:") 4 money_total = decimal.Decimal(money) 5 nums = int(input("请输入红包的个数:")) 6 for num in range(1,nums+1): 7 if num == nums: 8 last = money_total #最后一个人得所有未发出去的红包 9 else: 10 last = money_total/2*decimal.Decimal(str(random.random())) #限制单人红包大于总红包金额的一半 11 last = last.quantize(decimal.Decimal('0.00')) #四舍五入保留两位小数点 12 money_total = money_total - last 13 print("第%d个红包:%s" %(num,str(last)))
实战04(显示实时天气预报)
1 weather='2018年4月17日\t 天气预报:{:s} \t 20℃~7℃ \t 微风转西风3~4级 \n \ 2 08:00 \t 天气预报:{:s} \t 13℃ \t 微风 \n \ 3 12:00 \t 天气预报:{:s} \t 19℃ \t 微风 \n \ 4 16:00 \t 天气预报:{:s} \t 18℃ \t 西风3~4级 \n \ 5 20:00 \t 天气预报:{:s} \t 15℃ \t 西风3~4级 \n \ 6 00:00 \t 天气预报:{:s} \t 12℃ \t 微风 \n \ 7 04:00 \t 天气预报:{:s} \t 9℃ \t 微风' 8 context = weather.format('晴','晴','晴','晴','晴','晴','晴') 9 print(context)
标签:00,last,money,str1,print,Python5,天气预报 From: https://www.cnblogs.com/ron312/p/16755143.html