Learning notes for beginners on the first day-python loop control and the first python game, python-python

Source: Internet
Author: User

Learning notes for beginners on the first day-python loop control and the first python game, python-python
Three logic controls of Python

1. python syntax.

Python is based on indentation. The indentation of the same Code must be consistent. Otherwise, an error is reported.

1. Three loops of if

_ Age = 53

# Note that all input values are strings. To compare the input values with numbers, convert them to int values.

Age = int (input ("age :"))

If age> _ age:

Print ("older than the actual age ")

 

 

Age = int (input ("age :"))

If age> _ age:

Print ("older than the actual age ")

Else:

Pirnt ("less than or equal to the actual age ")

 

 

Age = int (input ("age :"))

If age> _ age:

Print ("older than the actual age ")

Elif age = _ age

Pirnt ("equal to actual age ")

Else:

Pirnt ("less than the actual age ")

 

2. Basic use of the for Loop
For I in range (3 ):

Print (I)

 

For I in range (1, 10, 2 ):

Print (I)

 

3. Practical Application of while

While I <44:

Print (I)

I + = 1

 

Use of Python logic control and break continue

1. break ends the overall loop (if there are multiple loops, only the first loop exists). The End Of The continue is to end a single loop.

Problem: the following two types of print cycles

For I in range (10 ):

Print ("------", I)

I = I + 1

For j in range (10 ):

Print (j)

J = j + 1

If j> 5:

Continue

Print ("test1 ")

Print ("test2 ")

 

For I in range (10 ):

Print ("------", I)

I = I + 1

For j in 1, 2, 3, 4, 5:

Print (j)

J = j + 1

If j> 5:

Break

Print ("test ")

 

Answer:

Last execution result (we can see that the external layer loop has no effect)

------ 9
0
Test continue
1
Test continue
2
Test continue
3
Test continue
4
Test continue
5
6
7
8
9
Test2

 

 

------ 9
0
Test continue
1
Test continue
2
Test continue
3
Test continue
4
Test continue
5
Comprehensive use of test2 Python logic control:

1. Guess the age. Three guesses are completed.

_ Age = 53

Count = 0

While count <3:

Count = count + 1

Print ("Enter your age ")

Age = input ("age :")

If age = _ age:

Print ("you got it ")

Break

If age> _ age:

Print ("age is bigger ")

Else:

Print ("age is simmer ")

Else:

Print ("game over ")

 

 

Homework after class:

If the user is in the blacklist, login is prohibited. If the user fails to log on three times, set it to the blacklist. If the user logs on successfully. Go to the welcome page. Files must be used for data storage:

 

 

 

  

 

 

 

Related 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.