Lesson two

来源:互联网 发布:c语言四则运算程序 编辑:程序博客网 时间:2024/05/14 04:19

Test 2:

<table class="highlighttable " style="border-collapse: collapse; margin: 0px -0.5em 0px 0.5em; color: rgb(0, 0, 0); font-family: ff-meta-web-pro-1, ff-meta-web-pro-2, Arial, 'Helvetica Neue', sans-serif; font-size: 16px; line-height: 24px;"><tbody><tr><td class="linenos" style="padding: 0px 0.5em;"><div class="linenodiv"><pre style="overflow-x: auto; overflow-y: hidden; font-family: Consolas, 'Deja Vu Sans Mono', 'Bitstream Vera Sans Mono', monospace; margin: 1em 0em; font-size: 0.95em; letter-spacing: 0.015em; line-height: 18.24px; padding: 5px 0px; border: 0px; border-radius: 6px; color: rgb(170, 170, 170); background-color: transparent;">1 2 3 4 5 6 7 8 91011121314151617181920212223

print "I will now count my chickens:"print "Hens", 25 + 30 / 6print "Roosters", 100 - 25 * 3 % 4print "Now I will count the eggs:"print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6print "Is it true that 3 + 2 < 5 - 7?"print 3 + 2 < 5 - 7print "What is 3 + 2?", 3 + 2print "What is 5 - 7?", 5 - 7print "Oh, that's why it's False."print "How about some more."print "Is it greater?", 5 > -2print "Is it greater or equal?", 5 >= -2print "Is it less or equal?", 5 <= -2


上节练习中主要学习了如何打印出内容和#的注释功能,这次我们来学习一下数学计算符,

首先让我们来学习一下各种计算符的英文吧

1.+ puls 加号

2.- miuns 减号

3./ slash 除号

4.* asterisk乘号

5.% percent百分号(取余运算符)

6.< less-than小于号

7.> Greater-than大于号

8.<=less-than-equal 小于等于号

9.>=greater-than-equal 大于等于号

书中就只有这些内容,以后若是还学到再来作补充。


python不同于C语言,表达式能直接运算不需要赋值给一个变量(就我目前的理解来看)

另外值得注意的一点是判断式如果为错会打印出false,反之是ture


Running result:

I will now count my chickens:Hens 30Roosters 97Now I will count the eggs:7Is it true that 3 + 2 < 5 - 7?FalseWhat is 3 + 2? 5What is 5 - 7? -2Oh, that's why it's False.How about some more.Is it greater? TrueIs it greater or equal? TrueIs it less or equal? False

Other topics:

书中说不能输出浮点数,可不知道为什么我写的一段代码

print10.2+2.4
能打印出来12.6(日后再来解答)


第二节的学习也到此为止了。



0 0
原创粉丝点击