Python video lecture 5 (notes and answers to exercises after class) and python lecture 5

Source: Internet
Author: User

Python video lecture 5 (notes and answers to exercises after class) and python lecture 5

Two days ago, I was lazy and didn't insist. I started today and hoped to stick to it,

Today we are mainly studying data types. For python, data types mainly include INTEGER (int), Boolean (bool), floating point (float), and E method (E)

For example, the integer (int) is mainly an integer, And the Boolean Type (bool) is judgment, true or false. Float contains the decimal point. The E notation is scientific.

There are several points to explain about the example:

1, type and isinstance. These two built-in functions are used to determine the type of a variable (integer or floating point type). The difference is that type mainly gives the type of a variable, and isinstance mainly judges the type of a variable.

2. For the bool type, as long as the value is not 0, all others are true,

3. the value in the integer (int) is truncated, that is

4. Use the E-note method. Pay attention to the error items in the example.

Hands-on part:

Import randomsecret = random. randint () I = 1 print ('-------------------- I love fish C studio ------------------') guess = 0 print ("guess which number the little turtle is thinking :") while (guess! = Secret) and (I <3): temp = str (input () I = I + 1 if temp. isdigit (): guess = int (temp) if guess = secret: print ("My grass, are you a worm in my heart ?! ") Print (" Hum, no reward even if you have guessed it! ") Else: if guess> secret: print (" brother, it's Big ~~~ ") Else: print (" Hey, small, small ~~~ ") Else: print (" You entered an error, please enter an integer: ") print (" the game is over, no play ^_^ ")

 

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.