python学习第三天
2016-01-13 00:00
861 查看
摘要: 继续学习
参考在线文档http://www.runoob.com/python/python-while-loop.html
#!/usr/bin/python
#filename:test3.py
a = 21
b = 10
c = 0
#part one : assignment operator
c = a + b
print ("Line 1 - Value if c is ",c)
c += a
print ("Line 2 - Value of c is ",c)
c *= a
print ("Line 3 - Value of c is ",c)
c /= a
print ("Line 4 - Value of c is ",c)
c = 2
c %= a
print ("Line 5 - Value of c is ",c)
c **=a
print ("Line 6 - Value of c is ",c)
c //=a
print ("Line 7 -Value of c is",c)
# part two : bit operator
a = 60
b = 13
c = 0
c = a & b
print ("Line 1 - Value of c is ",c)
c = a | b
print ("Line 2 - Value of c is ",c)
c = a ^ b
print ("Line 3 - Value of c is ",c)
c = ~a
print ("Line 4 - Value of c is ",c)
c = a << 2
print ("Line 5 - Value of c is ",c)
c = a >> 2
print (" Line 6 - Value of c is ",c)
#part three : logical operator
a = 10
b = 20
c = 0
if( a and b ):
print ("Line 1 - a and b are true ")
else :
print ("Line 1 - ether a or b is not true ")
if( a or b ):
print ("Line 2 - at least one of them is true ")
else :
print ("Line 2 - Neither a nor b is true")
a = 0
if( a and b ):
print ("Line 3 - a and b are true")
else:
print ("Line 3 - either a or b is not true")
if not( a and b):
print ("Line 5 - either a or b is not true")
else :
print ("Line 5 - a and b are true")
# part four
a = 20
b = 20
if( a is b):
print ("Line 1 - a and b have same identity")
else:
print ("Line 1 - a and b do not have same identity")
if( id(a) == id(b)):
print ("Line 2 - a and b have same identity")
else:
print ("Line 2 - a and b do not have same identity")
b = 30
if( a is b):
print ("Line 4 - a and b do not have same identity")
else:
print ("Line 4 - a and b do not have same identity")
if(a is not b ):
print ("Line 4 - a and b do not have same identity")
else:
print("Line 4 - a and b have the same identity")
#PART FIVE
a = 20
b = 10
c = 15
d = 5
e = 0
e = ( a + b )*c/d
print ("value of (a + b) * c / d is ",e)
e = ((a + b ) * c)/d
print ("value of ((a+b)*c)/d is ",e)
e = ( a + b) * (c / d)
print ("value of ( a + b) * (c/d) is ",e)
e = a + (b * c) /d
print ("Value of a + ( b * c)/d is ",e)
#PART SIX
num = 5
if num == 3:
print ("boss")
elif num == 2:
print ("user")
elif num ==1:
print ("worker")
elif num < 0 :
print ("error")
else:
print ("roadman")
num = 9
if num >= 0 and num <= 10:
print ("hello")
else:
print ("undefine")
if(num >=0 and num <= 5) or (num >= 10 and num <= 15):
print ("hello")
else:
print ("undefine")
参考在线文档http://www.runoob.com/python/python-while-loop.html
#!/usr/bin/python
#filename:test3.py
a = 21
b = 10
c = 0
#part one : assignment operator
c = a + b
print ("Line 1 - Value if c is ",c)
c += a
print ("Line 2 - Value of c is ",c)
c *= a
print ("Line 3 - Value of c is ",c)
c /= a
print ("Line 4 - Value of c is ",c)
c = 2
c %= a
print ("Line 5 - Value of c is ",c)
c **=a
print ("Line 6 - Value of c is ",c)
c //=a
print ("Line 7 -Value of c is",c)
# part two : bit operator
a = 60
b = 13
c = 0
c = a & b
print ("Line 1 - Value of c is ",c)
c = a | b
print ("Line 2 - Value of c is ",c)
c = a ^ b
print ("Line 3 - Value of c is ",c)
c = ~a
print ("Line 4 - Value of c is ",c)
c = a << 2
print ("Line 5 - Value of c is ",c)
c = a >> 2
print (" Line 6 - Value of c is ",c)
#part three : logical operator
a = 10
b = 20
c = 0
if( a and b ):
print ("Line 1 - a and b are true ")
else :
print ("Line 1 - ether a or b is not true ")
if( a or b ):
print ("Line 2 - at least one of them is true ")
else :
print ("Line 2 - Neither a nor b is true")
a = 0
if( a and b ):
print ("Line 3 - a and b are true")
else:
print ("Line 3 - either a or b is not true")
if not( a and b):
print ("Line 5 - either a or b is not true")
else :
print ("Line 5 - a and b are true")
# part four
a = 20
b = 20
if( a is b):
print ("Line 1 - a and b have same identity")
else:
print ("Line 1 - a and b do not have same identity")
if( id(a) == id(b)):
print ("Line 2 - a and b have same identity")
else:
print ("Line 2 - a and b do not have same identity")
b = 30
if( a is b):
print ("Line 4 - a and b do not have same identity")
else:
print ("Line 4 - a and b do not have same identity")
if(a is not b ):
print ("Line 4 - a and b do not have same identity")
else:
print("Line 4 - a and b have the same identity")
#PART FIVE
a = 20
b = 10
c = 15
d = 5
e = 0
e = ( a + b )*c/d
print ("value of (a + b) * c / d is ",e)
e = ((a + b ) * c)/d
print ("value of ((a+b)*c)/d is ",e)
e = ( a + b) * (c / d)
print ("value of ( a + b) * (c/d) is ",e)
e = a + (b * c) /d
print ("Value of a + ( b * c)/d is ",e)
#PART SIX
num = 5
if num == 3:
print ("boss")
elif num == 2:
print ("user")
elif num ==1:
print ("worker")
elif num < 0 :
print ("error")
else:
print ("roadman")
num = 9
if num >= 0 and num <= 10:
print ("hello")
else:
print ("undefine")
if(num >=0 and num <= 5) or (num >= 10 and num <= 15):
print ("hello")
else:
print ("undefine")
相关文章推荐
- Python爬虫学习稿(三)
- python学习记录(1)
- Python合并两个列表的方法
- python核心编程-正则表达式之-重复、特殊字符、子组
- [Python标准库]datetime——日期和时间值管理
- python---购物
- 运维:windows+python+route的一次相遇
- python列表推导的几个例子
- python入门-基础知识
- Using Django with GAE Python 后台抓取多个网站的页面全文
- python核心编程-正则表达式之-创建字符集合
- 【学神-RHEL7】P4-Python列表操作和字符串的常用方法
- python核心编程-正则表达式之-任意单个字符
- input和raw_input区别
- python学习第二天
- 《笨办法学Python》 第11课手记
- 正则表达式 口诀 学习正则的朋友看看
- python核心编程-正则表达式之-匹配多个字符串
- Python学习手册 - 11
- python核心编程之-search函数