美文网首页
笨办法学python第3课

笨办法学python第3课

作者: 3ab9db71c244 | 来源:发表于2018-08-30 18:42 被阅读10次
    print("i will now count my chickens:")  #打印字符
    print("hens", 25 + 30 / 6) #打印字符,且 计算25+30/6
    print("roosters", 100 -25 * 3 % 4)  #打印字符且计算 %指的是相除之后的余数 既75/4余数3
    print("now i will count the eggs:")  # #打印字符
    print(3 + 2 + 1 -5 + 4%2 -1/4 + 6)  #计算
    print("is it true that 3 + 2 < 5 -7?")    #在字符中判断,电脑会给出true 或者 false
    print(3 + 2 < 5- 7)  #判断大小
    print("what is 3 + 2?", 3 + 2)  #前面的是公式,后面会计算
    print("what is 5 - 7?", 5 -7)  #前面是字符串,后面会计算
    print("oh, that's why it's False")  #打印字符串
    print("how about some more.")  ##打印字符串
    print("is it greater?", 5 > -2) #前面有字符串,后面判断大小,系统会给true or false
    print("is it greater or equal?", 5>=-2)  #相当于是大于等于号
    print("is it less or equal", 5<= -2)  #相当于是小于等于号
    
    
    运行结果
    $ python3.6 ex3.py
    I will now count my chickens:
    Hens 30.0
    Roosters 97
    Now I will count the eggs:
    6.75
    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 greater or equal? True
    Is it less or equal? False
    
    练习题:
    1. Above each line, use the # to write a comment to yourself explaining what the line does.(给每一行注释)
    done
    2. Remember in Exercise 0 when you started python3.6? Start python3.6 this way again and,using the math operators, use Python as a calculator.(像第0课中那样重新做一遍,把python作为计算器)
    
    
    3. Find something you need to calculate and write a new .py file that does it.(找到需要计算的东西写一个新的文件)
    
    4. Rewrite ex3.py to use floating point numbers so it’s more accurate. 20.0 is floating point.(
    #重新做练习3,用带小数点的数字)
    
    常见问题
    1.%在python的运算符号中,代表着余数

    相关文章

      网友评论

          本文标题:笨办法学python第3课

          本文链接:https://www.haomeiwen.com/subject/lggkwftx.html