s = set(['Adam', 'Lisa', 'Bart', 'Paul'])
print s
print len(s)
print s
print len(s)
2015-12-24
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for a in d:
print a ,":",d[a]
for key,value in zip(d.keys(),d.values()):
print("%s:%s" %(key,value))
print("%s:%s" % (key,d[key]))
print("%s:%d" % (key,d[key]))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for a in d:
print a ,":",d[a]
for key,value in zip(d.keys(),d.values()):
print("%s:%s" %(key,value))
print("%s:%s" % (key,d[key]))
print("%s:%d" % (key,d[key]))
2015-12-24
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for a in d:
print a ,":",d[a]
for key,value in zip(d.keys(),d.values()):
print("%s:%s" %(key,value))
print("%s:%s" % (key,d[key]))
print("%s:%d" % (key,d[key]))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for a in d:
print a ,":",d[a]
for key,value in zip(d.keys(),d.values()):
print("%s:%s" %(key,value))
print("%s:%s" % (key,d[key]))
print("%s:%d" % (key,d[key]))
2015-12-24
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
print d
d[72]='Paul'
print d
d.update({72:'paul'})
print d
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
print d
d[72]='Paul'
print d
d.update({72:'paul'})
print d
2015-12-24
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
print d
d[72]='Paul'
print d
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
print d
d[72]='Paul'
print d
2015-12-24
# -*- coding: utf-8 -*-
d = {
95:'Adam',
85:'Lisa',
59:'Bart'
}
print d
key=95
print d[key]
d = {
95:'Adam',
85:'Lisa',
59:'Bart'
}
print d
key=95
print d[key]
2015-12-24
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key, value in zip(d.keys(), d.values()):
print("%s: %s" % (key, value))
for a in d:
print("%s: %s" % (a, d[a]))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key, value in zip(d.keys(), d.values()):
print("%s: %s" % (key, value))
for a in d:
print("%s: %s" % (a, d[a]))
2015-12-24
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:', d["Adam"]
print 'Lisa:', d['Lisa']
print 'Bart:', d['Bart']
for key in d:
print("%s: %s" % (key, d[key]))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:', d["Adam"]
print 'Lisa:', d['Lisa']
print 'Bart:', d['Bart']
for key in d:
print("%s: %s" % (key, d[key]))
2015-12-24
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59,
'Paul': 75
}
print d
print len(d)
'Adam': 95,
'Lisa': 85,
'Bart': 59,
'Paul': 75
}
print d
print len(d)
2015-12-24
sum = 0
x = 1
while x<=100:
if x/2!=0:
sum=sum+x
print sum
真是学以致用
x = 1
while x<=100:
if x/2!=0:
sum=sum+x
print sum
真是学以致用
2015-12-24
参考代码没有考虑b*b-4*a*c<0的情况,所以答案应该是这样的:
import math
def quadratic_equation(a, b, c):
x = b * b - 4 * a * c
if x < 0:
return none
elif x == 0:
return -b / (2 *a)
else:
return ((math.sqrt(x) - b ) / (2 * a)) , ((-math.sqrt(x) - b ) / (2 * a))
import math
def quadratic_equation(a, b, c):
x = b * b - 4 * a * c
if x < 0:
return none
elif x == 0:
return -b / (2 *a)
else:
return ((math.sqrt(x) - b ) / (2 * a)) , ((-math.sqrt(x) - b ) / (2 * a))
2015-12-24
def move(n, a, b, c):
if n==1:
return a +'-->'+c
return move(n-1,a,c,b)+a+' -->'+c+move(n-1,b,a,c)
print move(4, 'a', 'b', 'c')
if n==1:
return a +'-->'+c
return move(n-1,a,c,b)+a+' -->'+c+move(n-1,b,a,c)
print move(4, 'a', 'b', 'c')
2015-12-24
print 'HELLO,PYTHON'
print 'HELLO,',"PYTHON"
print 'HELLO,',"PYTHON"
2015-12-24