ll2 = [10*x+y for x in range(1,10) for y in range(10) if x < y]
for item in ll2:
print item
for item in ll2:
print item
2018-04-16
l2 = [10*x+y for x in range(1,10) for y in range(10) if x < y]
for item in l2:
print item
for item in l2:
print item
2018-04-16
age = 20
if age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
类似于Boolean的“短路计算”???
if age >= 6:
print 'teenager'
elif age >= 18:
print 'adult'
else:
print 'kid'
类似于Boolean的“短路计算”???
2018-04-16
尾数(末项)=首数(首项)+公差×(个数-1)
x100 = x1 + (n-1)*d
和=(末项+首项)×个数÷2
s = (x1 + x100)*n/2
x100 = x1 + (n-1)*d
和=(末项+首项)×个数÷2
s = (x1 + x100)*n/2
2018-04-16
def average(*args):
if (args !=None and len(args)>0):
return sum(args)*1.0/len(args)
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if (args !=None and len(args)>0):
return sum(args)*1.0/len(args)
else:
return 0.0
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-04-16
```
s = r'Python was started in 1989 by "Guido". Python is free and easy to learn.,'
print s
```
答案没换行。。。那就直接r了~
s = r'Python was started in 1989 by "Guido". Python is free and easy to learn.,'
print s
```
答案没换行。。。那就直接r了~
2018-04-15
```
x1 = 1
d = 3
n = 100
x100 = 1
s = x1
count = 0
while x100 < n:
s = s + x1 + x100 * d
count = count + 1
print s, x100, count
x100 = x100 + 1
print x100
print s
```
实验了下,莫名其妙的过了。。。
x1 = 1
d = 3
n = 100
x100 = 1
s = x1
count = 0
while x100 < n:
s = s + x1 + x100 * d
count = count + 1
print s, x100, count
x100 = x100 + 1
print x100
print s
```
实验了下,莫名其妙的过了。。。
2018-04-15
现去百度的韦达定理。。。。。
>>> def quadratic_equation(a,b,c):
... return (-b+math.sqrt(b**2-4*a*c))/2*a,(-b-math.sqrt(b**2-4*a*c))/2*a
...
>>> print quadratic_equation(2,3,0)
(0.0, -6.0)
>>> print quadratic_equation(1,-6,5)
(5.0, 1.0)
>>>
>>> def quadratic_equation(a,b,c):
... return (-b+math.sqrt(b**2-4*a*c))/2*a,(-b-math.sqrt(b**2-4*a*c))/2*a
...
>>> print quadratic_equation(2,3,0)
(0.0, -6.0)
>>> print quadratic_equation(1,-6,5)
(5.0, 1.0)
>>>
2018-04-15
>>> def square_of_sum(L):
... Lb = [x**2 for x in L]
... return sum(Lb)
...
>>>
>>> print square_of_sum([1,2,3,4,5])
55
>>> print square_of_sum([-5,0,5,15,25])
900
>>>
... Lb = [x**2 for x in L]
... return sum(Lb)
...
>>>
>>> print square_of_sum([1,2,3,4,5])
55
>>> print square_of_sum([-5,0,5,15,25])
900
>>>
2018-04-15