No. 1: The Path to python and No. 1 python

Source: Internet
Author: User

No. 1: The Path to python and No. 1 python

Introduction

AI is getting closer and closer to life. Here we will record the process of self-learning python and tensorflow. Programming IDE: visual studio 2017, python 3.6.3, and tensorflow 1.4.0

Body

Hello word implementation:

The print () function of python can output specified text, variables, and numbers to the screen. Variables and numbers can be output directly. The text must be enclosed in single or double quotation marks. For example:

print('hello word')

Hello word advanced:

When you need to output text with numbers or variables, you can simply use % d, % s, and so on. Example:

x = 5print('x=%d',x)

When you need to add a large number of other characters or numbers, you can use. format. Example:

Name = 'zhang 'score = 89 info =' {_ name} scored {_ score} 'in the test '. format (_ name = name, _ score = score) print (info)

Note:

# Can Be Used to annotate a single line in python, ''' can be used to annotate multiple rows, and ''' can also be used to define multiple line characters, for example:

# One Line comment ''' this is three lines comment '''

Console input:

In python, you can use the input () function to obtain console input. You can use quotation marks to output a prompt. For example:

X = input ('input x value :')

Judgment:

Python must pay attention to code indentation. The judgment statements mainly include if, elif, and else. Example:

If condition: Case 1 elif condition: Case 2 else: Case 3

Loop:

Python's loop functions mainly include while and. Both of them can determine else. The meaning of break and continue in the loop is the same as that in c ++. Example:

While condition: loop body else: when the condition is not true, execute for I in range: loop body else: when the condition is not true, execute

Job

Compile a multi-level query menu for the school department's official website:

Program flowchart:

 

# Python 3.6 ''' author: Kai Zfunction: department finder version: 1.0 ''' # define dictionary dic_of_ncepu = {'simulation and control lab ': {'HTTP: // 202.206.208.58/fksys/'}, 'School of Electrical and Electronic Engineering': {'department of Electrical Engineering ': {'HTTP: // 202.206.208.58/dianlixi /'}, department of Electronic and Communication Engineering: {'HTTP: // 202.206.208.57/dianzi/pub/home. asp '}}, 'School of energy, power and mechanical engineering': {'department of Power Engineering ': {'HTTP: // pe.ncepu.edu.cn/'}, 'department of Mechanical Engineering ': {'HTTP: // dme.ncepu.edu.cn/jixie/'}, 'School of control and computer engineering ': {'automation system': {'HTTP: // 202.206.20 8.57/automation/'}, 'computer system': {'HTTP: // jsjx.ncepu.edu.cn/computerWeb/index.php'}, 'economic Management Department ': {'HTTP: // 202.206.208.57/dianjing /'}, 'Emy of mathematics ': {' Emy of Mathematics (Beijing)': {'HTTP: // slx.ncepu.edu.cn/'},' Emy of Mathematics (Baoding)': {'HTTP: // 202.206.208.58/math/'}, 'Emy of mathematics': {' Emy of Mathematics (Beijing) ': {'HTTP: // slx.ncepu.edu.cn /'}, 'mathematical College (Baoding) ': {'HTTP: // 202.206.208.58/math/'}, 'College of Humanities and Social Sciences ': {'HTTP: // dlp.ncepu.edu.cn/'},' Emy of Foreign Languages': {'HTTP: // 202.206. 208.58/yyx/'}, 'School of Environmental Science and Engineering': {'HTTP: // 202.206.208.58/huangongxi/yemian/shouye/index. php '}, 'School of International Education': {'HTTP: // iei.ncepu.edu.cn/'}, 'marxist ': {'HTTP: // smarx.ncepu.edu.cn /'}, 'School of Science and Technology ': {'HTTP: // www.hdky.edu.cn/'}, 'department of Physical Education ': {'HTTP: // 202.206.208.57/txb/'}, 'School of Continuing Education ': {'HTTP: // www.hdcj.com/'}, 'art Education Center': {'HTTP: // 202.206.208.57/YiJiaoZhongXin/portal. php '}, 'engineering training Center': {'HTTP: // cet.ncepu.edu.cn /'},} Print (''' --------------- China North Electric Power University Department website query --------------- enter the Department to query (enter q to exit ):''') company = ''# predefined unit while company! = 'Q': department = input () if department = 'q': break elif not department in dic_of_ncepu: print ('this system is not found. Please input it again ') continue else: if len (dic_of_ncepu [department]) = 1: print (dic_of_ncepu [department]) else: print ('Enter the subordinate units of the department to be queried: (return by B, exit by q) ') while True: company = input () if company =' B ': print ('back to the upper level') break elif company = 'q ': break elif not company in dic_of_ncepu [department]: print ('this unit is not found, please enter again') continue else: print (dic_of_ncepu [department] [company])

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.