1. 程式人生 > >9.13作業2(完整溫度轉換、數字遊戲、解析身份證號...)

9.13作業2(完整溫度轉換、數字遊戲、解析身份證號...)

網址 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 in
range (1,250): 2 print(http://news.gzcc.cn/html/xiaoyuanxinwen/+str(i)+.html)

運行結果:

技術分享圖片

9.13作業2(完整溫度轉換、數字遊戲、解析身份證號...)