Python Learning notes (i)

Source: Internet
Author: User
Tags ming

1, the most basic IO statement

Name=input ()

Print (' Hello, ', name)

2, Python also allows to use R ' ' to indicate that the string inside of ' is not escaped by default

Print (' \\\t\\ ')

Print (R ' \\\t\ ')

3, null value is expressed as none, but not understood as 0. Because 0 is meaningful.

4. Java is a static language, and variable types must be specified when defining variables. Python is a dynamic language and more flexible.

5. a= ' abc '

B=a

A= ' XYZ '

Print (b)

Indicates that the variable B points to the data that the variable a points to, and the result of print variable B is ' abc '.

6, ASCII encoding is a byte, Unicode encoding is two bytes, UTF-8 encoding compared to save space.

Unicode encoding is used uniformly in computer memory and converted to UTF-8 encoding when saved to hard disk or transmitted.

In versions above Python3, the strings are encoded in Unicode.

7.

>>> s1=72
>>> s2=85
>>>r= (S2-S1)/float (S1) *100

>>> print ('%.1f%% '%r)
18.1%

8, the tuple is immutable, try to use a tuple instead of list. When defining a tuple, the elements of a tuple must be determined.

9.

10.

11.

Practice

Xiao Ming is 1.75 tall and weighs 80.5kg. Please help Xiao Ming calculate his BMI according to the BMI formula (weight divided by the square of height) and according to the BMI Index:

    • Less than 18.5: too light
    • 18.5-25: Normal
    • 25-28: Overweight
    • 28-32: Obesity
    • Above 32: Severe obesity

To if-elif determine and print the result:

Height=float (Input (' Please enter height '))
Weight=float (Input (' Please enter weight '))
bmi=weight/(height**2)
If bmi<18.5:
Print (' BMI is%.2f, too light '%bmi)
Elif bmi>=18.5 and bmi<=25:
Print (' BMI is%.2f normal '%bmi)
Elif bmi>25 and bmi<=28:
Print (' BMI is%.2f, overweight '%bmi)
Elif Bmi>28and bmi<=32:
Print (' BMI is%.2f, fat '%bmi)
Else
Print (' BMI is%.2f, severely obese '%bmi)

Python Learning notes (i)

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.