for x in [ 1,2,3,4,5,6,7,8]:
for y in [2,3,4,5,6,7,8,9]:
#print x*10+y
if x<y:
print x*10+y
for y in [2,3,4,5,6,7,8,9]:
#print x*10+y
if x<y:
print x*10+y
2020-03-03
我执行了下面一段代码:
a = 'python'
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
c = 'python'
print 'hello,', c and 'world'
d = ''
print 'hello,', d and 'world'
执行结果如下:
hello, python
hello, world
hello, world
hello,
a = 'python'
print 'hello,', a or 'world'
b = ''
print 'hello,', b or 'world'
c = 'python'
print 'hello,', c and 'world'
d = ''
print 'hello,', d and 'world'
执行结果如下:
hello, python
hello, world
hello, world
hello,
2020-03-02
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.values():
sum=sum+i
s=sum*1.0/len(d)
print s
sum = 0.0
for i in d.values():
sum=sum+i
s=sum*1.0/len(d)
print s
2020-03-01
个人觉得挺好(~ ̄▽ ̄)~
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print sum(d.values())/(len(d)*1.0)
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
print sum(d.values())/(len(d)*1.0)
2020-03-01
def square_of_sum(L):
sum=0
for i in L:
sum+=i*i
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum=0
for i in L:
sum+=i*i
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2020-02-29
L = []
sum=0
for i in range(100):
L.insert(i,(i+1)*(i+1))
sum=sum+L[i]
print sum
sum=0
for i in range(100):
L.insert(i,(i+1)*(i+1))
sum=sum+L[i]
print sum
2020-02-29
L = []
sum=0
x=1
for i in range(100):
L.insert(i,x*x)
sum=sum+L[i]
x+=1
print sum
sum=0
x=1
for i in range(100):
L.insert(i,x*x)
sum=sum+L[i]
x+=1
print sum
2020-02-29
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k,v in d.items():
print k,v
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k,v in d.items():
print k,v
2020-02-29
执行L.pop(2) 删除 ‘Paul’,这时‘Bart’的下标会变成L(2),所以L.pop(3)应该改成L.pop(2)
2020-02-29
a or 'word' :a为 true,取a
b or 'word' :b为 false,取'word'
b or 'word' :b为 false,取'word'
2020-02-29
L = [75, 92, 59, 68]
sum = 0.0
for i in range(4):
sum+=L[i]
print sum / 4
sum = 0.0
for i in range(4):
sum+=L[i]
print sum / 4
2020-02-28