def firstCharUpper(s):
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[:1].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2018-05-21
def average(*args):
if args:
return float(sum(args)) / len(args)
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if args:
return float(sum(args)) / len(args)
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-05-21
import math
def quadratic_equation(a, b, c):
if (b*b-4*a*c) > 0:
x1 = (-b+math.sqrt(b*b-4*a*c))/(2*a)
x2 = (-b-math.sqrt(b*b-4*a*c))/(2*a)
return x1,x2
else:
return
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
if (b*b-4*a*c) > 0:
x1 = (-b+math.sqrt(b*b-4*a*c))/(2*a)
x2 = (-b-math.sqrt(b*b-4*a*c))/(2*a)
return x1,x2
else:
return
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-05-21
有个偷鸡的办法,但是只能py2,玩玩还是行的:
print [int("{0}{1}{0}".format(x,y)) for x in range(10) for y in range(10)][10:]
print [int("{0}{1}{0}".format(x,y)) for x in range(10) for y in range(10)][10:]
2018-05-20
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
if 'Paul' in d:
print d['Paul']
else:
print 'ok'
print d['Adam']
print d.get('Lisa')
print d.get('Bart')
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
if 'Paul' in d:
print d['Paul']
else:
print 'ok'
print d['Adam']
print d.get('Lisa')
print d.get('Bart')
2018-05-20
a=range(0,10)
J=(k*100+m*10+n for k in range(1,10) for m in a for n in a if k==n)
print(list(J))
哈哈哈终于结束了入门,各位看到这里的也快了~我先去中级了拜拜~
J=(k*100+m*10+n for k in range(1,10) for m in a for n in a if k==n)
print(list(J))
哈哈哈终于结束了入门,各位看到这里的也快了~我先去中级了拜拜~
2018-05-18