import math
def quadratic_equation(a, b, c):
if b**2-4*a*c>0:
nx=(-b+math.sqrt(b**2-4*a*c))/(2*a)
ny=(-b-math.sqrt(b**2-4*a*c))/(2*a)
return nx,ny
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
只写了△大于0时情况,足够过编译了。注意书写格式
def quadratic_equation(a, b, c):
if b**2-4*a*c>0:
nx=(-b+math.sqrt(b**2-4*a*c))/(2*a)
ny=(-b-math.sqrt(b**2-4*a*c))/(2*a)
return nx,ny
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
只写了△大于0时情况,足够过编译了。注意书写格式
2019-07-26
ef square_of_sum(L):
x=len(L)
i=0
a=0
while i<x:
p=L[i]*L[i]
a+=p
i+=1
if i==x:
return a
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
注意格式
x=len(L)
i=0
a=0
while i<x:
p=L[i]*L[i]
a+=p
i+=1
if i==x:
return a
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
注意格式
2019-07-26
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for b in L:
if b in s:
s.remove(b)
else:
s.add(b)
print s
注意书写格式,是空格别打table
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for b in L:
if b in s:
s.remove(b)
else:
s.add(b)
print s
注意书写格式,是空格别打table
2019-07-25
L = []
x=1
while x<=100:
L.append(x*x)
x=x+1
print sum(L)
x=1
while x<=100:
L.append(x*x)
x=x+1
print sum(L)
2019-07-25
sum = 0
x = 1
while x < 100:
if x % 2 != 0:
sum = sum + x
x = x + 1
print (sum)
x = 1
while x < 100:
if x % 2 != 0:
sum = sum + x
x = x + 1
print (sum)
2019-07-25
print(45678+int(0x12fd2))
print("Learn Python in imooc")
print(100<99)
print(0xff==255)
print("Learn Python in imooc")
print(100<99)
print(0xff==255)
2019-07-24
print('hello python.')
i='hello,'
n='python.'
print(i+n)
i='hello,'
n='python.'
print(i+n)
2019-07-23
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for x in d.values():
sum=sum+x
print sum/len(d.values())
sum = 0.0
for x in d.values():
sum=sum+x
print sum/len(d.values())
2019-07-21
# 两种方法都可以
for x in [ 0,1,2,3,4,5,6,7,8,9]: # 表示个位
for y in [1,2,3,4,5,6,7,8,9]: # 表示十位
if y < x:
print(y,x,end=", ")
print()
for x in [ 1,2,3,4,5,6,7,8,9]: # 表示十位
for y in [0,1,2,3,4,5,6,7,8,9]: # 表示个位
if x < y:
print (x,y)
for x in [ 0,1,2,3,4,5,6,7,8,9]: # 表示个位
for y in [1,2,3,4,5,6,7,8,9]: # 表示十位
if y < x:
print(y,x,end=", ")
print()
for x in [ 1,2,3,4,5,6,7,8,9]: # 表示十位
for y in [0,1,2,3,4,5,6,7,8,9]: # 表示个位
if x < y:
print (x,y)
2019-07-21
# 两种方法都可以,
for x in [ 0,1,2,3,4,5,6,7,8,9]: # 表示十位
for y in [1,2,3,4,5,6,7,8,9]: # 表示个位
if y < x:
print(y,x,end=", ")
print()
for x in [ 1,2,3,4,5,6,7,8,9]: # 表示十位
for y in [0,1,2,3,4,5,6,7,8,9]: # 表示个位
if x < y:
print (x,y)
for x in [ 0,1,2,3,4,5,6,7,8,9]: # 表示十位
for y in [1,2,3,4,5,6,7,8,9]: # 表示个位
if y < x:
print(y,x,end=", ")
print()
for x in [ 1,2,3,4,5,6,7,8,9]: # 表示十位
for y in [0,1,2,3,4,5,6,7,8,9]: # 表示个位
if x < y:
print (x,y)
2019-07-21
def move(n,a,b,c):
if n ==1:#如果只有一个原盘
print a,’-->',c#将a直接移到c
return#退出
move(n-1,a,c,b)#否则将a上的n-1个圆盘以c为辅助轴移动到b上
move(1,a,b,c)#将a上的底盘移动到c
if n ==1:#如果只有一个原盘
print a,’-->',c#将a直接移到c
return#退出
move(n-1,a,c,b)#否则将a上的n-1个圆盘以c为辅助轴移动到b上
move(1,a,b,c)#将a上的底盘移动到c
2019-07-20