sum = 0
x = 1
n = 1
while True:
if x > 20:
break
sum += pow(2, x-1)
x += 1
print sum
x = 1
n = 1
while True:
if x > 20:
break
sum += pow(2, x-1)
x += 1
print sum
2016-01-08
为整数型
for x in [ 10,20,30,40,50,60,70,80,90]:
for y in [ 0,1,2,3,4,5,6,7,8,9 ]:
if x/10<y :
print x+y
如果为字符型
for x in ['1','2','3','4','5','6','7','8','9']:
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
for x in [ 10,20,30,40,50,60,70,80,90]:
for y in [ 0,1,2,3,4,5,6,7,8,9 ]:
if x/10<y :
print x+y
如果为字符型
for x in ['1','2','3','4','5','6','7','8','9']:
for y in ['1','2','3','4','5','6','7','8','9']:
if x < y:
print x + y
2016-01-08
x = 1 #赋值语句
d = 3 #赋值语句
s = 0 #求和S
n = 0 #循环终止条件
while n < 100: #n < 100 相当于循环100次~
#注意以下依次顺序~
s += x #如第一次X是1,第二次是4,第三次是7,依次相加上去1+4+7....
x += 3 #参考s += x
n += 1 #参考s += x
print (s) #打印s
#抄袭其它同学
d = 3 #赋值语句
s = 0 #求和S
n = 0 #循环终止条件
while n < 100: #n < 100 相当于循环100次~
#注意以下依次顺序~
s += x #如第一次X是1,第二次是4,第三次是7,依次相加上去1+4+7....
x += 3 #参考s += x
n += 1 #参考s += x
print (s) #打印s
#抄袭其它同学
2016-01-08
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
print set(L) - s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
print set(L) - s
2016-01-08
我居然在纠结 print 'hello,', a or 'world' 中的 , 是什么鬼..
2016-01-07
已采纳回答 / 小猫过河
有,自带的 IDLE(gui)。安装了插件的其它IDE都可以,如果会vim,命令行里就可以直接写代码了。另外,命令行里输入python回车,也可以写python语句,当然大程序这样写不方便。
2016-01-07
s = 1+4+7+10+...+(1+3*99)
= 100+3+6+9+...+3*99
= 100+3*1+3*2+3*3+...+3*99
= 100+3*(1+99)*49+3*50
= 100+14700+150
= 14950
= 100+3+6+9+...+3*99
= 100+3*1+3*2+3*3+...+3*99
= 100+3*(1+99)*49+3*50
= 100+14700+150
= 14950
2016-01-07
L = ['Adam', 'Lisa', 'Bart']
L.insert(2,'Paul')
print L
L.insert(2,'Paul')
print L
2016-01-07
a = 'python'
print 'hello,', a or 'world'
# hello,'python'
b = ''
print 'hello,', b or 'world'
# hello world
print 'hello,', a or 'world'
# hello,'python'
b = ''
print 'hello,', b or 'world'
# hello world
2016-01-07
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.'''
2016-01-07
L = ['Adam', 'Lisa', 'Bart']
L[0] = 'Bart'
L[-1]= 'Adam'
print L
L[0] = 'Bart'
L[-1]= 'Adam'
print L
2016-01-07