Self-learning Python core programming

Source: Internet
Author: User

I've seen a little turtle before. 0 Basic self-study Python,b station with high-definition free resources [av4050443], but as the 0 Foundation is hard to learn, download the Python core programming pdf, here to do some notes.

Although the use of the second edition of the textbook, but I use the python3.5.2, the feeling is not very different, can read.

Here is the beginning of the second chapter of the exercises!

--------------------------------------------------------

2-5: Print with while and for 0-10:

i = 0

While I < 11:

Print (i)

i + = 1

------------

For I in range (11):

Print (i)

---------------------------------------------

2-7: Input string and print, use while and for:

Str_input = input (' Please enter string: ')

i = 0

While I < Len (str_input):

Print (Str_input[i])

i + = 1

-----------

Str_input = input (' Please enter string: ')

For I in Str_input:

Print (i)

--------------------------------------------------------------

2-8: Enter 5 numbers to add:

i = 0

temp = 0

While I < 5:

temp + = Int (input (' Please enter a number: '))

i + = 1

Print (temp)

--------------

temp = 0

For I in range (5):

temp + = Int (input (' Please enter a number: '))

Print (temp)

------------------------------------------------------

2-9: Output The average of five values:

temp = 0

For I in range (5):

temp + = Int (input (' Please enter a number: '))

Arverange = TEMP/5

Print (Arverange)

------------------------------------------------------------

2-10: Determine whether to enter 1 to 100, is to stop, otherwise re-enter:

num = Int (input (' Please enter an integer between 1 and 100: '))

While Num isn't in range (2,101):

Print (' incorrect input ')

num = Int (input (' Please enter an integer between 1 and 100: '))

Print (' You're right! ')

--------------

Using recursion seems troublesome, I'm not quite sure (see below):

def function1 (num):

If 1 < num < 100:

Print (' Your number in (1,100) ')

Else

Print (' The number you are input is not in (1,100) ')

num = Int (input (' please input a number: '))

Function1 (num)

num = Int (input (' please input a number: '))

Function1 (num)

---------------------------------------------------------------

Self-learning Python core programming

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.