sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
elif x % 2 == 0:
continue
sum += x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
elif x % 2 == 0:
continue
sum += x
print sum
2020-05-08
思考题
age = 8
if age >= 18:
print 'adult'
elif age>6:
print 'teenage'
else:
print 'kid'
age = 8
if age >= 18:
print 'adult'
elif age>6:
print 'teenage'
else:
print 'kid'
2020-05-07
# 十六进制数据必须加上括号才行
print(45678+(0x12fd2))
print('Learn Python in imooc')
print(100<99)
print((0xff)==255)
print(45678+(0x12fd2))
print('Learn Python in imooc')
print(100<99)
print((0xff)==255)
2020-05-06
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for key in d:
print key,':',d[key]
2020-05-03
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
count=len(d)
for i in d.itervalues():
sum +=i
print sum/count
sum = 0.0
count=len(d)
for i in d.itervalues():
sum +=i
print sum/count
2020-05-01
def average(*args):
if len(args) == 0:
return 0.0
else:
sums=0.0
for i in args:
sums=sums+i
return sums/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args) == 0:
return 0.0
else:
sums=0.0
for i in args:
sums=sums+i
return sums/len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2020-05-01
def square_of_sum(L):
sums=0
for i in L:
sums+=i*i
return sums
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sums=0
for i in L:
sums+=i*i
return sums
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2020-05-01
sums=0
for x in range(1,101):
for xx in range(1,101):
if(x==xx):
sums+=x*xx
print sums
for x in range(1,101):
for xx in range(1,101):
if(x==xx):
sums+=x*xx
print sums
2020-05-01