Getting started with Python first article

Source: Internet
Author: User

Day.1

A.python Foundation

1. Basic

Print ('helloWorld')

2. Operating Environment

# inside the file: #    # !/usr/bin/env python # file name: #    . /2. py#Linux Environment in order to run ## in the PY3 environment without adding, PY2 head must be added ==> environment in the default use of ASCII interpretation, So Chinese explanation does not pass ##  -*-Coding:utf8-*-

3. Variable ==> can be understood as Unknown X (FOG)

Note: Variables can only be made up of letters, numbers, and underscores.

Exception: 1. Cannot start with a number

2.python keywords cannot be used: [' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' fin Ally ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' tr ' Y ', ' while ', ' with ', ' yield ']

3. It's best not to repeat the python built-in stuff.

4. Conditional Statement ①if ==> Else

1 """The format is as follows2 if ( how how How):3 deal with what?4 Else: (else can be omitted)5 deal with what?6 """7 #For example #8Password =Input (Please enter password:)9 if(password = 123456):#The default password is 123456# #注意if和else后有个冒号 #Ten     Print("Password is correct") One Else: A     Print("Password Error")

②if ==> Elif

1user_name = input ("Please enter your login account")2 if("user_name = = Administrator"):3     Print("welcome, Super Admin")4 elif("user_name = = Forbidden Flower")5     Print("Welcome, Forbidden Flower")6 elif("user_name = = Guest")7     Print("Welcome, Guest")8 Else:9     Print("Please sign up for a new account or log in with a Guest account")

③while ==> Break & Continue

1 """ 2 The format is as follows 3 While True 4     handle how 5     loops until the condition is not true.  6"" "7#break forced interrupt Loop #8#  Continue exit the current loop and continue the next loop #

Exercises:

1. Use while loop input 1 2 3 4 5 6 8 9 10

1 count = 12 while (Count <=):3     if(count = = 7):  4         count = Count + 15         continue6     else:  7         print  (count)8     count = count + 1
Exercises 1

2. For all numbers of 1-100

1 count = 12 a1 = 03 while (Count <=):4     a1 = A1 + Count 5     Count = Count + 16Print(A1)
Exercises 2

3. All odd numbers in output 1-100

1 count = 12while (Count <=):3     if (count% 2 = = 1): /c7>4         print(count)5     else:6         Pass7     count = count + 1
Exercises 3

4. All even numbers in output 1-100

(See Exercise 3)

5, Beg 1-2+3-4+5 ... 99 of all numbers of the and

1 count = 12 a1 = 03while (count<100):4     if (count% 2 = = 1):5         a1 = A1 + count6     else:  7         a1 = A1- count8     count = count + 19Print(A1)
Exercises 5

6, the user login (three times the opportunity to retry) (the password is correct, the wrong prompt password error, error 3 times after the prompt to log in tomorrow)

1Count = 42  while(Count >0):3passkey = input ('Please enter your password:')4     if(passkey = ="123456"):5         Print("Password is correct")6          Break7     Else:8         Print("password error, number of times left")9Count = count-1Ten         Print(count) One         if(Count = =0): A             Print("Please try again tomorrow .") -         Else: -             Pass
Exercises 6

Getting started with Python first article

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.