sum = 0
x = 1
n = 1
while True:
sum = sum+ x
x=x*2
n = n+1
if n>20:
break
print (sum)
x = 1
n = 1
while True:
sum = sum+ x
x=x*2
n = n+1
if n>20:
break
print (sum)
2018-07-19
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(-1)
L.pop(-1)
print L
L.pop(-1)
L.pop(-1)
print L
2018-07-19
for x in range(1,10):
for y in range(1,10):
if x<y:
print x*10+y
for y in range(1,10):
if x<y:
print x*10+y
2018-07-19
# -*- coding: utf-8 -*-
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
print '''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
2018-07-19
print r'''"To be, or not to be": that is the question.
whether it's nobler in the mind to suffer.'''
在3.3以上版本加括号
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.'''
在3.3以上版本加括号
print(r'''"To be, or not to be": that is the question.
whether it's nobler in the mind to suffer.''')
2018-07-19
def average(*args):
sum=0.0
if len(args)==0:
return sum
for x in args:
sum+=x
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
sum=0.0
if len(args)==0:
return sum
for x in args:
sum+=x
return sum/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-07-19
print r'''"To be, or not to be": that is the question.\nWhether it's nobler in the mind to suffer.'''
2018-07-19
x1 = 1
d = 3
n = 100
x100 = x1 +(n-1)*d
s = (x100+x1)*n / 2
print(s)
d = 3
n = 100
x100 = x1 +(n-1)*d
s = (x100+x1)*n / 2
print(s)
2018-07-19
多行注释用三个单引号 ''' 或者三个双引号 """ 将注释括起来
'''
这是多行注释,用三个单引号
这是多行注释,用三个单引号
这是多行注释,用三个单引号
'''
print("Hello, World!")
'''
这是多行注释,用三个单引号
这是多行注释,用三个单引号
这是多行注释,用三个单引号
'''
print("Hello, World!")
2018-07-19
L = ['Adam', 'Lisa', 'Bart', 'Paul']
M = []
for x in L:
y = x.lower()
M.append(y)
s = set(M+L)
print('adam' in s)
print('bart' in s)
print('Bart' in s)
M = []
for x in L:
y = x.lower()
M.append(y)
s = set(M+L)
print('adam' in s)
print('bart' in s)
print('Bart' in s)
2018-07-19
s = "Python was started in 1989 by \"Guido\".\n Python is free and easy to learn."
print s
print s
2018-07-18