NO.1:自學python之路

來源:互聯網
上載者:User

標籤:返回   代碼   pytho   continue   inpu   相同   break   rtm   ati   

引言

人工智慧如今越來越貼近生活,在這裡將記錄我自學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 = 5print(‘x=%d‘,x)

當需要大量加入其他字元或數字時,可以使用.format完成,例子:

name = ‘小張‘score = 89info = ‘{_name}在考試中得了{_score}分’.format(_name = name,_score = score)print(info)

注釋:

python中注釋單行可以使用 # ,注釋多行時可以使用 ‘‘‘ ,同時 ’‘’ 也可以定義多行字元,例子:

#一行注釋‘‘‘這是三行注釋‘‘‘

控制台輸入:

python中可以使用input()函數獲得控制台輸入。括弧中可以用引號輸出提示,例子:

x = input(‘輸入x的值:‘)

判斷:

python一定要注意代碼的縮排。判斷的語句主要有if,elif,else。例子:

if 條件:    情況1elif 條件:    情況2else:    情況3

迴圈:

python的迴圈函數主要有while和for。它們都可以判斷else。迴圈中break與continue與c++中意義相同不再贅述。例子:

while 條件:    迴圈體else:    條件不成立時執行for i in range(範圍):    迴圈體else:    條件不成立時執行

作業

編寫一個多級的學校院系官網查詢菜單:

程式流程圖:

 

# Python 3.6‘‘‘author:   Kai Zfunction: 華北電力大學院系查詢器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之路

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.