9.13课堂作业
(1)温度的条件语句转化
while True: a = int(input("摄氏温度转为华氏温度按1\n华氏温度转为摄氏温度按2\n")) if a == 1: shuru = float(input('请输入摄氏度:')) jisuan = (shuru * 1.8) + 32 print('{}摄氏温度转为华氏温度为{}'.format(shuru,jisuan)) elif a == 2: huashi = float(input('请输入华氏温度:')) yunsuan = 5 / 9 * (huashi - 32) print('{}华氏温度转为摄氏温度为{}'.format(huashi, yunsuan)) else: break
(2)猜数字游戏
number = 9 j = -1 print('猜数字游戏') while j != number: j = int(input('请输入你的数字,区间为1-10\n')) if j == number: print('你猜对了!') elif j>number: print('数字大了!') else: print('数字小了!')
(3)解析身份证号码,学号
d = input('请输入身份号码:\n') print('省份:{},地区:{},县级:{},出生日期:{},识别码:{},'.format(d[0:2],d[2:4],d[4:6],d[6:14],d[-1])) if int(d[-2])%2==0: print('性别:女') else: print('性别:男') y = '150327199507181818' print("你的所属省份:"+y[0:2]) print("你的所属地区:"+y[2:4]) print("你的所属县级:"+y[4:6]) print("你的出生日期:"+y[6:14]) print("你的派出所代码:"+y[14:16]) if int(y[-2])%2==0: print('性别:女') else: print('性别:男')
q = '201606050045'
print('年级:{},班级:{},号码:{},'.format(q[0:4],q[4:8],q[8:12]))
(4)字符串的连接、提取、in运算
s = '12345686584'
r = '156'
print(s+r)
print('2'in s) print(r'C:\Intel\Logs')
(5)建立网址
for i in range(2,23):
print('http://news.gzcc.cn/html/xiaoyuanxinwen/'+str(i)+'.html')
print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i))
(6)用for循环遍历字符串
k = '我是小仙女呀' for c in k: print (c)