L = ['Adam', 'Lisa', 'Bart']
L[-1],L[0] = L[0],L[-1]
print L
L[-1],L[0] = L[0],L[-1]
print L
2019-09-21
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
if key == 'Adam':
print key + ":" +str(d['Adam'])
if key == 'Lisa':
print key + ':' +str(d['Lisa'])
if key == 'Bart':
print key + ':' +str(d['Bart'])
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
if key == 'Adam':
print key + ":" +str(d['Adam'])
if key == 'Lisa':
print key + ':' +str(d['Lisa'])
if key == 'Bart':
print key + ':' +str(d['Bart'])
2019-09-21
import math
def quadratic_equation(a, b, c):
t=math.sqrt(b**2-4*a*c)
return (-b+t)/2/a,(-b-t)/2/a
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
t=math.sqrt(b**2-4*a*c)
return (-b+t)/2/a,(-b-t)/2/a
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2019-09-20
def square_of_sum(L):
sum=0
for i in L:
sum+=i**2
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum=0
for i in L:
sum+=i**2
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2019-09-20
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print('%s:%d'%(x[0],x[1]))
for x in s:
print('%s:%d'%(x[0],x[1]))
2019-09-20
months = set(['Feb'])
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
2019-09-20
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print("%s:%d"%(name,d[name]))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print("%s:%d"%(name,d[name]))
2019-09-20
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print('Adam: %d'%d['Adam'])
print('Lisa: %d'%d.get('Lisa'))
print('Bart: %d'%d['Bart'])
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print('Adam: %d'%d['Adam'])
print('Lisa: %d'%d.get('Lisa'))
print('Bart: %d'%d['Bart'])
2019-09-20
for x in [1,2,3,4,5,6,7,8]:
for y in [2,3,4,5,6,7,8,9]:
if x<y: print(str(x)+str(y))
for y in [2,3,4,5,6,7,8,9]:
if x<y: print(str(x)+str(y))
2019-09-20
#Enter a code
print(45678+0x12fd2)
print('Lern Python in imooc')
print(100<99)
print(0xff==255)
print(45678+0x12fd2)
print('Lern Python in imooc')
print(100<99)
print(0xff==255)
2019-09-19
x1 = 1
d = 3
n = 100
x100 = x1 + d * 99
s = x1 * 100 + 99 * 50 * d
print s
d = 3
n = 100
x100 = x1 + d * 99
s = x1 * 100 + 99 * 50 * d
print s
2019-09-19
#Enter a code
#coding=utf-8
print 45678 + 0x12fd2
print 'Learn Python in imooc。'
print 100 < 99
print 0xff == 255
#coding=utf-8
print 45678 + 0x12fd2
print 'Learn Python in imooc。'
print 100 < 99
print 0xff == 255
2019-09-19