学习python的第二天
来源:互联网 发布:期货套利分析软件 编辑:程序博客网 时间:2024/05/18 00:28
注释和“#”号
在学习一门编程语言的时候,最重要的事一定少不了看程序里的注释。一般情况注释有两个功能:第一,可以通过自然语言的方式告诉你某段代码的作用;第二,在运行程序的时候想要禁用某些代码,可以先用注释将代码临时禁用。
练习部分
# A comment, this is so you can read your program later.# Anything after the # is ignored by python.print "I could have code like this. "# and the comment after is ignored#you can also use a comment to "disable" or comment out a piece of code:#print "This won't run."print "This will run."
数字和数学计算
在这章中,我们将接触数学运算符号:
+
加号-
减号/
斜杠*
星号%
百分号<
小于号>
大于号<=
小于等于号>=
大于等于号
以上的符号都是用来做运算的,通过练习可以学习这些符号的作用。
练习部分
print "I will now count my chickens:"print "Hens",25 + 30 /6print "Roosters", 100 - 25 * 3 % 4print "How 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.用#
在每句代码前写一个注释,说明作用
2.使用浮点数重新写一遍ex3.py
# 输出 I will now count my chickens:print "I will now count my chickens:"# 计算 Hensprint "Hens",25.0 + 30 /6# 计算 Roostersprint "Roosters", 100.0 - 25 * 3 % 4# 输出 How I will count the eggs:print "How I will count the eggs:"# 计算 eggsprint 3.0 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6# 输出 Is it true that 3 + 2 < 5 - 7 ?print "Is it true that 3 + 2 < 5 - 7 ?"# 判断 3 + 2 和 5 - 7 的关系,输出结果print 3.0 + 2 < 5 - 7# 计算 3 + 2print "What is 3 + 2 ?",3.0 + 2# 计算 5 - 7print "What is 5 - 7 ?",5.0 - 7# 输出 Oh,that's why it's False.print "Oh,that's why it's False."# 输出 How about some more.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 0
- 学习python的第二天
- 学习python的第二天
- 学习Python第二天
- 学习第二天python
- Python 学习第二天
- Python学习第二天
- 学习python第二天
- 学习python第二天
- Python学习第二天
- python学习第二天
- python 学习第二天
- python学习第二天
- 学习python第二天
- Python学习第二天
- 第二天学习python
- python--学习第二天
- Python 学习 第二天
- 【学习Python】第二天
- GPIO输出操作—使用固件库点亮LED--- 调试总结
- Android音频焦点处理相关的方法
- 行人检测论文阅读(2)
- Mac Sublime text3 for Nodejs Developer Environment Configation
- AfxBeginThread的介绍/基本用法和GetWindowTextA函数
- 学习python的第二天
- JSONP跨域的原理解析及其实现介绍
- 归并排序
- TXT导入数据到SQL
- 二级浮动菜单(angularjs2 + css)
- HDU 1074 Doing Homework(状压DP+记录路径)
- 画贝兹曲线
- [JS]删除链表重复所有结点3
- Ubuntu 环境变量