The way to learn Python

Source: Internet
Author: User
Tags for in range

Introduction

AI is now more and more close to life, here will record my self-taught Python and tensorflow process. Programming using Ide:visual Studio 2017,python version 3.6.3,tensorflow version 1.4.0

Body

Hello Word implementation:

The print () function of Python allows you to specify text, variables, and numbers to the screen output. Variables and numbers can be directly output, the text need to add single or double quotation marks, example:

Print ('Hello word')

Hello Word Advanced:

When you need to output text with numbers or variables, simple can be done by%d,%s, etc., example:

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

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

' Xiao Zhang '  = _name= ' {_score} ' in the exam. Format (_name = Name,_score = score)print(info)

Comments:

A comment line in Python can use #, commenting on multiple rows can be used ", and also can define multi-line characters, example:

# One line of comments " " This is a three line comment " "

Console input:

You can use the input () function in Python to get console input. You can use quotation marks to output hints in parentheses, for example:

x = input (' value of input x:')

Judge:

Python must be aware of the indentation of the code. The sentences of judgment are mainly if,elif,else. Example:

if Condition: Condition    1elif  Condition: Condition    2else:    condition 3

Cycle:

The loop function of Python mainly has while and for. They can all judge else. The break in the loop and the continue in C + + do not dwell on the same meaning. Example:

 while condition:    loop body else: Execute for in range    when condition is not set   :    loop body Else :    execution when conditions are not established

Homework

Write a multi-level school Department official website Query menu:

Program Flowchart:

#Python 3.6" "Author:kai zfunction: Ncepu Hospital finder version:1.0" "#Defining DictionariesDic_of_ncepu = {    'Simulation and Control laboratory':{        '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 Department':{            'http://202.206.208.57/automation/'            },        'Computer Department':{            'http://jsjx.ncepu.edu.cn/computerWeb/index.php'            }        },    'Department of Economic Management':{        'http://202.206.208.57/dianjing/'        },    'School of Mathematics':{        'School of Mathematics (Beijing)':{            'http://slx.ncepu.edu.cn/'            },        'School of Mathematics (Baoding)':{            'http://202.206.208.58/math/'            }        },    'School of Mathematics':{        'School of Mathematics (Beijing)':{            'http://slx.ncepu.edu.cn/'            },        'School of Mathematics (Baoding)':{            'http://202.206.208.58/math/'            }        },    'Faculty of Humanities and Social sciences':{        'http://dlp.ncepu.edu.cn/'        },    'Foreign Language Institute':{        'http://202.206.208.58/yyx/'        },    'School of Environmental Science and engineering':{        'http://202.206.208.58/huangongxi/yemian/shouye/index.php'        },    'International Institute of Education':{        'http://iei.ncepu.edu.cn/'        },    'Marxist College':{        'http://smarx.ncepu.edu.cn/'        },    'College of Science and Technology':{        'http://www.hdky.edu.cn/'        },    'Department of Physical Education':{        'http://202.206.208.57/txb/'        },    'College of Continuing Education':{        'http://www.hdcj.com/'        },    'Arts Education Center':{        'http://202.206.208.57/YiJiaoZhongXin/portal.php'        },    'Engineering Training Center':{        'http://cet.ncepu.edu.cn/'        },    }Print(" "---------------NCEPU Department Web site Query---------------Please enter the department you want to query (enter Q exit):" ") Company="'#pre-defined units whileCompany! ='Q': Department=input ()ifDepartment = ='Q':         Break    elif  notDepartmentinchDic_of_ncepu:Print('The system is not queried, please re-enter')        Continue    Else:        ifLen (dic_of_ncepu[department]) = = 1:            Print(Dic_of_ncepu[department])Else:            Print('Please enter the subordinate units of the department you are inquiring about: (press B to return, press Q to exit)')             whileTrue:company=input ()ifCompany = ='b':                    Print('back to previous level')                     Break                elifCompany = ='Q':                     Break                elif  notCompanyinchDic_of_ncepu[department]:Print('The unit is not queried, please re-enter')                    Continue                Else:                    Print(Dic_of_ncepu[department][company])

The way to learn Python

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.