sum = 0
x = 1
while x % 2 != 0 and x < 100:
x+=sum
print sum
x = 1
while x % 2 != 0 and x < 100:
x+=sum
print sum
2015-10-28
L = [75, 92, 59, 68]
sum = 0.0
for age in L:
sum+=age
print sum / 4
sum = 0.0
for age in L:
sum+=age
print sum / 4
2015-10-28
L = [75, 92, 59, 68]
sum = 0.0
for age in L:
sum+=age
print sum / 4
sum = 0.0
for age in L:
sum+=age
print sum / 4
2015-10-28
t = ('a', 'b', ('A', 'B'))
print t
print t
2015-10-27
t = tuple(range(10))
print 't =',t
[root@Derrick-nb-85 ~]# python 1.py
t = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
print 't =',t
[root@Derrick-nb-85 ~]# python 1.py
t = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
2015-10-27
不改变列表内容只能这样了
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print [L[2]]
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print [L[2]]
2015-10-27
在ide里面的结果就是1048575……在这里却不能提交
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=2**n
n=n+1
if n > 19 :
break
print sum
sum = 0
x = 1
n = 1
while True:
sum=sum+x
x=2**n
n=n+1
if n > 19 :
break
print sum
2015-10-27
print r'''"To be,or not to be": that is the question.\nWhether it's nobler in the mind to suffer.'''
2015-10-27
L = [75, 92, 59, 68]
sum = 0.0
for a in L:
sum=sum+a
print sum / 4.0
sum = 0.0
for a in L:
sum=sum+a
print sum / 4.0
2015-10-27
这一系列条件判断会 从上到下 依次判断,如果某个判断为 True,执行完对应的代码块,后面的条件判断就直接忽略,不再执行了。
age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
age = 20
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
2015-10-27
L = [95.5,85,59]
print L[0]
print L[1]
print L[2]
print L[3]
这种运行不了
L = [95.5,85,59]
print 95.5
print 85
print 59
print 59
这样就过le ........
print L[0]
print L[1]
print L[2]
print L[3]
这种运行不了
L = [95.5,85,59]
print 95.5
print 85
print 59
print 59
这样就过le ........
2015-10-27
A and B 运算:全真为真,一假为假,由于短路运算法则,因此,当A为true值,则结果取决于B的值;当A为false值,则结果为false
A or B 运算:一真为真,全假为假,~~~~,当A为true值,则结果为真;当A为假值,则结果取决于B的值
A or B 运算:一真为真,全假为假,~~~~,当A为true值,则结果为真;当A为假值,则结果取决于B的值
2015-10-27