Optimized for yesterday's code, with 14 lines to achieve the same functionality as yesterday
The code is as follows:
Print (' Welcome to the BMI calculation \ n ')
H=float (' Please enter your height (m): ')
W=float (Input (' Please enter your weight (kg): ')
s=w/(H*H)
If s<18.5:
Print (' Your BMI is: ', S, ' \ n is a bit thinner ~ a little fatter will be healthier oh ')
Elif s<=25:
Print (' Your BMI is: ', S, ' \ n Normal weight ~ is very healthy. Good, good. "
Elif s<=28:
Print (' Your BMI is: ', S, ' \ n is a bit overweight, exercise program can start ')
Elif s<=32:
Print (' Your BMI is: ', S, ') lose weight and lose weight. We are all potential shares ~ ')
Else
Print (' Your BMI is: ', S, ' \ n ') high body fat can cause a variety of complications oh, stick to exercise. ')
Today continue to learn python, loop.
There is a for x in .... Loops and while loops
The former is to put each element into a variable to think, and then execute the Indentation block statement, the latter is as long as the conditions are constant cycle, the condition is not satisfied to exit the loop.
The sum () and range () functions are also contacted.
Still do not do too much explanation, part of the content has paper notes. Here's my practice.
Use the loop to print the Hello xxx! for each name in the list, in turn:
#-*-Coding:utf-8-*-
L = [' Bart ', ' Lisa ', ' Adam ']
Here's the code names=[' Michael ', ' Lisa ', ' Adam '
For name in Names:
Print ("Hello," +name)
Run correctly.
You can also use a while to implement the following:
L = [' Bart ', ' Lisa ', ' Adam ']
n = 0
While N < Len (L):
Print (' Hello:%s! '% l[n])
n = n + 1
Run correctly.
If you write a dead loop statement, you can either exit the program with CTRL + C or force the end of the Python program.
I tried to write a Python dead loop statement that was fun, but no inspiration, and it might come true tomorrow.
Today also learned about the use of Dict (dictionary) and set,python has a built-in dictionary: dict support, Dict full name dictionary, also known as a map in other languages, using key-value (Key-value) storage, Has a very fast search speed.
Compared with list, Dict has the following characteristics: Find and insert the speed is very fast, not with the increase of key and slow, need to occupy a lot of memory, memory waste much.
The list is the opposite: the time to find and insert increases as the element increases;
So, Dict is a way of exchanging space for time.
Dict can be used in many places where there is a need for high-speed lookups, almost everywhere in Python code, and it is important to use dict correctly, and the first thing to remember is that dict key must be immutable .
This is because Dict calculates the storage location of value based on key, and if the same key is calculated differently each time, the dict is completely messed up. This algorithm, which uses the key to compute the position, is called a hash algorithm.
To ensure the correctness of the hash, the object as a key cannot be changed. In Python, strings, integers, and so on are immutable, so it's safe to be a key. And the list is variable, it can't be a key.
Set and dict are similar, and are collections of a set of keys, but do not store value. Because key cannot be duplicated, there is no duplicate key in set.
To create a set, you need to provide a list as an input set, and we can add elements to set by adding them, but without effect, through the Remove (key) method, you can delete the elements. Set can be regarded as a mathematical sense of unordered and no repeating elements of the set, therefore, two sets can do the mathematical sense of intersection, and set of operations.
So far, the basic knowledge of Python has been basically completed, followed by the knowledge of functions.
That's it.
Learn the basics of CSS tomorrow.