d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for n in d.itervalues():
sum=sum+n
print sum/len(d)
sum = 0.0
for n in d.itervalues():
sum=sum+n
print sum/len(d)
2019-03-07
第一小题比较容易理解,第二小题中
b=''
print 'hello,' , '' or 'world'中,逗号分隔两边为独立部分
因此会打印出hello,然后因为''为空值,在布尔类型中为false,
所以'' or world 在布尔短路运算中''false 继续运算打印world
因此 b=''
print 'hello,' , '' or 'world'打印出 hello world
b=''
print 'hello,' , '' or 'world'中,逗号分隔两边为独立部分
因此会打印出hello,然后因为''为空值,在布尔类型中为false,
所以'' or world 在布尔短路运算中''false 继续运算打印world
因此 b=''
print 'hello,' , '' or 'world'打印出 hello world
2019-03-07
# -*- coding: utf-8 -*-
print r'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
print r'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
2019-03-07
sum = 0
n = 0
while True:
sum = sum + 2**n
n = n + 1
if n > 19:
break
print sum
n = 0
while True:
sum = sum + 2**n
n = n + 1
if n > 19:
break
print sum
2019-03-06
import math
def ow(a,b,c):
if a==0:
x1=-c/b
x2=-c/b
return(x1,x2)
elif a!=0:
x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)
x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)
return(x1,x2)
x1,x2=ow(0,1,2)
print(x1,x2)
x1,x2=ow(1,2,1)
print(x1,x2)
def ow(a,b,c):
if a==0:
x1=-c/b
x2=-c/b
return(x1,x2)
elif a!=0:
x1=(-b+math.sqrt(b**2-4*a*c))/(2*a)
x2=(-b-math.sqrt(b**2-4*a*c))/(2*a)
return(x1,x2)
x1,x2=ow(0,1,2)
print(x1,x2)
x1,x2=ow(1,2,1)
print(x1,x2)
2019-03-05
def square_of_sum(L):
lst=[]
for x in L:
lst.append(x*x)
print(lst)
return(sum(lst))
print(square_of_sum([1, 2, 3, 4]))
lst=[]
for x in L:
lst.append(x*x)
print(lst)
return(sum(lst))
print(square_of_sum([1, 2, 3, 4]))
2019-03-05
list=[]
for x in range(1,11,1):
list.append(x*x)
print(list)
print(sum(list))
for x in range(1,11,1):
list.append(x*x)
print(list)
print(sum(list))
2019-03-05
#-*-coding:utf-8-*-
print (r'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
print (r'''静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。''')
2019-03-04
def square_of_sum(L):
sum = 0
for i in L:
sum = sum + i*i
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 = sum + i*i
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2019-03-04
L = []
for i in range(100):
L.append((i+1)*(i+1))
print sum(L)
for i in range(100):
L.append((i+1)*(i+1))
print sum(L)
2019-03-04