最简单的结果
def firstCharUpper(s):
return s[0].upper()+s[1::]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
def firstCharUpper(s):
return s[0].upper()+s[1::]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2018-12-29
x1 = 1
d = 3
n = 100
x100 = (n-1)*d+x1
s = (x1+x100)*n/2
print s
d = 3
n = 100
x100 = (n-1)*d+x1
s = (x1+x100)*n/2
print s
2018-12-29
偷个小懒……
print [x for x in range(100,1000) if x%10 == x//100 ]
print [x for x in range(100,1000) if x%10 == x//100 ]
2018-12-28
L = ['Adam', 'Lisa', 'Bart']
a=L[2]
L[2]=L[0]
L[0]=a
print L
a=L[2]
L[2]=L[0]
L[0]=a
print L
2018-12-28
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0 :
continue
sum=sum+x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0 :
continue
sum=sum+x
print sum
2018-12-27
sum = 0
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n> 20:
break
print sum
x = 1
n = 1
while True:
sum += x
x *= 2
n += 1
if n> 20:
break
print sum
2018-12-27
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
2018-12-27
因为是按照从上到下的顺序依次判断,当某一条件判断为T时,就直接打印结果,不再继续判断之后的条件,所以应该这样改:
age = 8
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
age = 8
if age >= 18:
print 'adult'
elif age >= 6:
print 'teenager'
else:
print 'kid'
2018-12-27
import math
def quadratic_equation(a, b, c):
X = b*b-4*a*c
if X < 0:
return false
elif X == 0:
return -b/(2*a)
else:
return ((-b)+math.sqrt(X))/(2*a), ((-b)-math.sqrt(X))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
X = b*b-4*a*c
if X < 0:
return false
elif X == 0:
return -b/(2*a)
else:
return ((-b)+math.sqrt(X))/(2*a), ((-b)-math.sqrt(X))/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-12-27
L = []
n = 0
while cmp(n, 100) < 0:
n = n+1
L.append(n*n)
print sum(L)
n = 0
while cmp(n, 100) < 0:
n = n+1
L.append(n*n)
print sum(L)
2018-12-27
sum = 0
x = 1
n = 1
while True:
sum=x+sum
x=2*x
n=n+1
if n>20:
break
print(sum)
x = 1
n = 1
while True:
sum=x+sum
x=2*x
n=n+1
if n>20:
break
print(sum)
2018-12-26