9.13作業2(完整溫度轉換、數字遊戲、解析身份證號...)
阿新 • • 發佈:2018-09-13
網址 ren mage code pan .cn 溫度 img image
1.完成完整的溫度轉換程序
輸入代碼:
1 a = input(‘"攝氏轉華氏請按1\n華氏轉攝氏請按2\n"‘) 2 3 if a == ‘1‘: 4 # 用戶輸入攝氏溫度 5 celsius = float(input(‘請輸入攝氏溫度‘)) 6 # 計算華氏溫度 7 fahrenheit = (celsius * 1.8) + 32 # f = c*9/5+32 8 # 向用戶輸出華氏溫度 9 print(‘{:.2f}攝氏溫度轉為華氏溫度為{:.2f}‘.format(celsius, fahrenheit)) 10 else: 11 fahrenheit = float(input(‘請輸入華氏溫度:‘)) 12 celsius = 5 / 9 * (fahrenheit - 32) 13 print(‘{:.2f}華氏溫度轉為攝氏溫度為{:.2f}\n‘.format(fahrenheit,celsius))
運行代碼:
2.猜數字遊戲
輸入代碼:
運行代碼:
3.解析身份證號、學號不同片段含義
(身份證號)輸入代碼:
1 a = input(‘請輸入身份證號碼:‘) 2 print(‘省份:‘,format(a[0:2]),‘地區:‘,format(a[2:4]),‘縣級:‘,format(a[4:6]),‘出生日期:‘,format(a[6:14])) 3 if int(a[-2]) % 2!=0: 4 print(‘性別:男‘) 5 else: 6 print(‘性別:女‘)
運行結果:
(學號)輸入代碼:
1 a = input(‘請輸入學號:‘) 2 print(print(‘年級:‘,format(a[0:4]),‘專業:‘,format(a[4:7]),‘班級:‘,format(a[7:10]),‘序號:‘,format(a[10:12])))
運行結果:
5.用for循環產生一系列網址;
輸入代碼:
1 for i inrange (1,250): 2 print(‘http://news.gzcc.cn/html/xiaoyuanxinwen/‘+str(i)+‘.html‘)
運行結果:
9.13作業2(完整溫度轉換、數字遊戲、解析身份證號...)