Every programming language has a mathematical computing method. programmers often think that they are mathematical geniuses. In fact, they are not. If they are mathematical geniuses, they will do mathematical-related work, instead of making little money by writing advertising programs and social games.
We don't know any mathematical symbols. Everyone knows. Go directly to the Code:
[Python]
1. print "I will now count my chickens :"
2.
3.
4. print "Hens", 25 + 30/6
5. print "Roosters", 100-25*3% 4
6.
7.
8. print "Now I will count the eggs :"
9.
10.
11. print 3 + 2 + 1-5 + 4% 2-1/4 + 6
12.
13.
14. print "Is it true that 3 + 2 <5-7? "
15.
16.
17. print 3 + 2 <5-7
18.
19.
20. print "What is 3 + 2? ", 3 + 2
21. print "What is 5-7? ", 5-7
22.
23.
24. print "Oh, that's why it's False ."
25.
26.
27. print "How about some more ."
28.
29.
30. print "Is it greater? ", 5>-2
31. print "Is it greatet or equal? ", 5> =-2
32. print "is it less or equal? ", 5 <=-2
The running result is as follows:
Root @ he-desktop :~ /Mystuff # python ex3.py
I will now count my chickens:
Hens 30
Roosters 97
Now I will count the eggs:
7
Is it true that 3 + 2 <5-7?
False
What is 3 + 2? 5
What is 5-7? -2
Oh, that's why it's False.
How about some more.
Is it greater? True
Is it greatet or equal? True
Is it less or equal? False
Root @ he-desktop :~ /Mystuff #
Extra score exercise
1. Add a comment to each line.
# Percentage indicates the remainder.
Print "Roosters", 100-25*3% 4
2. Like exercise (0), input python in Terminal, run python, and execute the above Code one by one.
3. Find a task and write a py file.
4. Check if the above program is incorrect. You will find that there are only integers without decimals. Search for and learn about the "floating point number ".
5. Write ex3.py with floating point numbers to make the results more correct.
Modify the 5th sentence:
Print 3 + 2 + 1-5 + 4% 2-1.0/4 + 6
The result after running is: 6.75
Author: lixiang0522