NO.1:自學python之路
阿新 • • 發佈:2018-02-10
代碼 流程圖 意義 .com log ont index.php 環境 分享
引言
人工智能如今越來越貼近生活,在這裏將記錄我自學python與tensorflow的過程。編程使用IDE:visual studio 2017,python版本3.6.3,tensorflow版本1.4.0
正文
hello word實現:
python的print()函數可以向屏幕輸出指定文字,變量,數字。變量和數字可以直接輸出,文字需要加入單引號或者雙引號,例子:
print(‘hello word‘)
hello word進階:
當需要將文字與數字或變量一同輸出時,簡單的可以靠%d,%s等完成,例子:
x = 5 print(‘x=%d‘,x)
當需要大量加入其他字符或數字時,可以使用.format完成,例子:
name = ‘小張‘ score = 89 info = ‘{_name}在考試中得了{_score}分’.format(_name = name,_score = score) print(info)
註釋:
python中註釋單行可以使用 # ,註釋多行時可以使用 ‘‘‘ ,同時 ’‘’ 也可以定義多行字符,例子:
#一行註釋 ‘‘‘這是 三行 註釋‘‘‘
控制臺輸入:
python中可以使用input()函數獲得控制臺輸入。括號中可以用引號輸出提示,例子:
x = input(‘輸入x的值:‘)
判斷:
python一定要註意代碼的縮進。判斷的語句主要有if,elif,else。例子:
if 條件: 情況1 elif 條件: 情況2 else: 情況3
循環:
python的循環函數主要有while和for。它們都可以判斷else。循環中break與continue與c++中意義相同不再贅述。例子:
while 條件: 循環體 else: 條件不成立時執行 for i in range(範圍): 循環體 else: 條件不成立時執行
作業
編寫一個多級的學校院系官網查詢菜單:
程序流程圖:
# Python 3.6 ‘‘‘ author: Kai Z function: 華北電力大學院系查詢器 version: 1.0‘‘‘ #定義字典 dic_of_ncepu = { ‘仿真與控制實驗室‘:{ ‘http://202.206.208.58/fksys/‘ }, ‘電氣與電子工程學院‘:{ ‘電力工程系‘:{ ‘http://202.206.208.58/dianlixi/‘ }, ‘電子與通信工程系‘:{ ‘http://202.206.208.57/dianzi/pub/home.asp‘ } }, ‘能源動力與機械工程學院‘:{ ‘動力工程系‘:{ ‘http://pe.ncepu.edu.cn/‘ }, ‘機械工程系‘:{ ‘http://dme.ncepu.edu.cn/jixie/‘ } }, ‘控制與計算機工程學院‘:{ ‘自動化系‘:{ ‘http://202.206.208.57/automation/‘ }, ‘計算機系‘:{ ‘http://jsjx.ncepu.edu.cn/computerWeb/index.php‘ } }, ‘經濟管理系‘:{ ‘http://202.206.208.57/dianjing/‘ }, ‘數理學院‘:{ ‘數理學院(北京)‘:{ ‘http://slx.ncepu.edu.cn/‘ }, ‘數理學院(保定)‘:{ ‘http://202.206.208.58/math/‘ } }, ‘數理學院‘:{ ‘數理學院(北京)‘:{ ‘http://slx.ncepu.edu.cn/‘ }, ‘數理學院(保定)‘:{ ‘http://202.206.208.58/math/‘ } }, ‘人文與社會科學學院‘:{ ‘http://dlp.ncepu.edu.cn/‘ }, ‘外國語學院‘:{ ‘http://202.206.208.58/yyx/‘ }, ‘環境科學與工程學院‘:{ ‘http://202.206.208.58/huangongxi/yemian/shouye/index.php‘ }, ‘國際教育學院‘:{ ‘http://iei.ncepu.edu.cn/‘ }, ‘馬克思主義學院‘:{ ‘http://smarx.ncepu.edu.cn/‘ }, ‘科技學院‘:{ ‘http://www.hdky.edu.cn/‘ }, ‘體育教學部‘:{ ‘http://202.206.208.57/txb/‘ }, ‘繼續教育學院‘:{ ‘http://www.hdcj.com/‘ }, ‘藝術教育中心‘:{ ‘http://202.206.208.57/YiJiaoZhongXin/portal.php‘ }, ‘工程訓練中心‘:{ ‘http://cet.ncepu.edu.cn/‘ }, } print(‘‘‘ ---------------華北電力大學院系網址查詢--------------- 請輸入要查詢的院系(輸入q退出): ‘‘‘) company = ‘‘#預定義單位 while company != ‘q‘: department = input() if department == ‘q‘: break elif not department in dic_of_ncepu: print(‘未查詢到該系,請重新輸入‘) continue else: if len(dic_of_ncepu[department]) == 1: print(dic_of_ncepu[department]) else: print(‘請輸入所查詢院系的下屬單位:(按b返回,按q退出)‘) while True: company = input() if company == ‘b‘: print(‘返回上一級‘) break elif company == ‘q‘: break elif not company in dic_of_ncepu[department]: print(‘未查詢到該單位,請重新輸入‘) continue else: print(dic_of_ncepu[department][company])
NO.1:自學python之路