sum = 0
x = 1
n = 1
while True:
sum += pow(2,n)
if n == 19:
break
n += 1
print(sum+x)
x = 1
n = 1
while True:
sum += pow(2,n)
if n == 19:
break
n += 1
print(sum+x)
2018-12-04
求教
sum = 0
x = 1
while x<=100 and x%2!=0:
sum=sum+x
print sum
为什么输出结果为0
sum = 0
x = 1
while x<=100 and x%2!=0:
sum=sum+x
print sum
为什么输出结果为0
2018-12-04
不加u是OK的 # -*- coding: utf-8 -*-
print '''
静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。
'''
print '''
静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。
'''
2018-12-03
s = 'Python was started in 1989 by \"Guido\".\nPython is free and easy to learn.'
print s
print s
2018-12-03
x1 = 1
d = 3
n = 100
x100 = x1 + d * (n-1)
#s = ???
s = 0
for h in range(1,101):
if h > 0:
m = x1 + d * (h-1)
s = s + m
print(s)
d = 3
n = 100
x100 = x1 + d * (n-1)
#s = ???
s = 0
for h in range(1,101):
if h > 0:
m = x1 + d * (h-1)
s = s + m
print(s)
2018-12-03
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
\\直接这样子就好了
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
\\直接这样子就好了
2018-12-03
def average(*args):
if len(args) > 0:
return float(sum(args))/len(args)
else:
return 0.0
if len(args) > 0:
return float(sum(args))/len(args)
else:
return 0.0
2018-12-03
def move(n, a, b, c):
if n == 1:
print a, '-->', c #打印头和尾
return
move(n-1, a, c, b) #B、C对调
print a, '-->', c #打印头和尾 即 A-B
move(n-1, b, a, c) #A、B对调 回到上面打印
move(4, 'A', 'B', 'C')
if n == 1:
print a, '-->', c #打印头和尾
return
move(n-1, a, c, b) #B、C对调
print a, '-->', c #打印头和尾 即 A-B
move(n-1, b, a, c) #A、B对调 回到上面打印
move(4, 'A', 'B', 'C')
2018-12-02