print(45678+0x12fd2)
print('Learn Python in imooc')
print(100 < 99)
print(0xff == 255)
print('Learn Python in imooc')
print(100 < 99)
print(0xff == 255)
2016-08-02
已采纳回答 / 冬冬_Allen7D
去掉return none,一旦执行rerurn,程序立马停止。因为无论如何递归,最底层的函数必定最先输出n==1时的情况,之后就return了,停止运行。
2016-08-02
#要多注意四则运算的优先级和括号
import math
def quadratic_equation(a, b, c):
d = b*b-4*a*c
if d < 0:
return None
else:
x1 = (-b+math.sqrt(d))/(2*a)
x2 = (-b-math.sqrt(d))/(2*a)
return x1, x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
import math
def quadratic_equation(a, b, c):
d = b*b-4*a*c
if d < 0:
return None
else:
x1 = (-b+math.sqrt(d))/(2*a)
x2 = (-b-math.sqrt(d))/(2*a)
return x1, x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2016-08-02
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,':', d.get(name)
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,':', d.get(name)
2016-08-02
a = 'python'
print 'hello,', a or 'world'
符合短路计算,返回'hello,', a 这个值就是hello,python
b = ''
print 'hello,', b or 'world'
b为空值是false 先运行左边的 'hello,', b 输出是hello, 再与 or 'world'运算,输出true的结果:hello,world
print 'hello,', a or 'world'
符合短路计算,返回'hello,', a 这个值就是hello,python
b = ''
print 'hello,', b or 'world'
b为空值是false 先运行左边的 'hello,', b 输出是hello, 再与 or 'world'运算,输出true的结果:hello,world
2016-08-02
print [int(m+n+m) for m in '123456789' for n in '0123456789']
2016-08-02
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
2016-08-02
x1 = 1
d = 3
n = 100
x100=n*(2*x1+(n-1)*d)/2
s = x100
print s
#卧槽,为撒子我把这个化简了一下就不行了,现在想知道这个运算符号的优先程度
# x100=x1*n+n*(n-1)*d/2
d = 3
n = 100
x100=n*(2*x1+(n-1)*d)/2
s = x100
print s
#卧槽,为撒子我把这个化简了一下就不行了,现在想知道这个运算符号的优先程度
# x100=x1*n+n*(n-1)*d/2
2016-08-01
>>> def fact(n):
if n==1:
return 1
return n * fact(n - 1)
fact(5)
SyntaxError: invalid syntax
>>>
if n==1:
return 1
return n * fact(n - 1)
fact(5)
SyntaxError: invalid syntax
>>>
2016-08-01