# 接上面
else:
x1 = str(((-1) * b) / (2 * a)) + "+" + str(math.sqrt(-pan)/(2 * a)) + 'i'
x2 = str(((-1) * b) / (2 * a)) + "-" + str(math.sqrt(-pan)/(2 * a)) + 'i'
return x1, x2
x1, x2 = quadratic_equation(1, 4, 6)
print(x1)
print(x2)
print(quadratic_equation(1, -6, 5))
else:
x1 = str(((-1) * b) / (2 * a)) + "+" + str(math.sqrt(-pan)/(2 * a)) + 'i'
x2 = str(((-1) * b) / (2 * a)) + "-" + str(math.sqrt(-pan)/(2 * a)) + 'i'
return x1, x2
x1, x2 = quadratic_equation(1, 4, 6)
print(x1)
print(x2)
print(quadratic_equation(1, -6, 5))
2019-07-20
import math
def quadratic_equation(a, b, c):
pan = b * b - 4 * a * c
if pan >= 0:
x1 = (-b + math.sqrt(pan)) / 2 / a
x2 = (-b - math.sqrt(pan)) / 2 / a
# 下面还有else,因为不能超过300个字。
def quadratic_equation(a, b, c):
pan = b * b - 4 * a * c
if pan >= 0:
x1 = (-b + math.sqrt(pan)) / 2 / a
x2 = (-b - math.sqrt(pan)) / 2 / a
# 下面还有else,因为不能超过300个字。
2019-07-20
练习结果如下:
#Enter a code
print(45678+0x12fd2)
print("Learn Python in imooc")
print(100<99)
print(0xff==255)
#Enter a code
print(45678+0x12fd2)
print("Learn Python in imooc")
print(100<99)
print(0xff==255)
2019-07-19
for x in [ 0,1,2,3,4,5,6,7,8,9 ]:
for y in [0,1,2,3,4,5,6,7,8,9 ]:
if x*10+y<10:
continue
if x<y:
print(x*10+y)
for y in [0,1,2,3,4,5,6,7,8,9 ]:
if x*10+y<10:
continue
if x<y:
print(x*10+y)
2019-07-19
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
2019-07-19
sum = 0
x = 1
n = 1
while True:
x=2**(n-1)
n=n+1
sum=sum+x
if n>20:
break
print sum
x = 1
n = 1
while True:
x=2**(n-1)
n=n+1
sum=sum+x
if n>20:
break
print sum
2019-07-19
L = [75, 92, 59, 68]
sum = 0.0
for a in L:
sum=sum+a
print sum / 4
sum = 0.0
for a in L:
sum=sum+a
print sum / 4
2019-07-19
print r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.'''
Whether it's nobler in the mind to suffer.'''
2019-07-18
print (r'''"To be, or not to be": that is the question.
Whether it's nobler in the mind to suffer.''')
Whether it's nobler in the mind to suffer.''')
2019-07-16
s = 'Python was started in 1989 by "Guido".\nPython is free and easy to learn.'
print s
print s
2019-07-16
x1 = 1
d = 3
n = 100
x100 = (n-1)*d+x1
s = (x1+x100)*n/2
print s
x1 = 1
d = 3
n = 100
d = 3
n = 100
x100 = (n-1)*d+x1
s = (x1+x100)*n/2
print s
x1 = 1
d = 3
n = 100
2019-07-16
print("hello,python.")
print("hello,"+"python.")
print("hello,"+"python.")
2019-07-16
a=45678
b=0x12fd2
print(a+b)
c="Learn Python in imooc"
print(c)
print bool(100<99)
print bool(0xff==255)
仅供参考,运行成功
b=0x12fd2
print(a+b)
c="Learn Python in imooc"
print(c)
print bool(100<99)
print bool(0xff==255)
仅供参考,运行成功
2019-07-16
a=45678
b=int(0x12fd2)
c=a+b
print c
print 'Learn Python in imooc'
print(100<99)
print(255==0xff)
运行成功
b=int(0x12fd2)
c=a+b
print c
print 'Learn Python in imooc'
print(100<99)
print(255==0xff)
运行成功
2019-07-16