# -*- coding: utf-8 -*-
print '''
静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
不用加u
print '''
静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。'''
不用加u
2018-04-07
def average(*args):
if len(args)==0:
return 0.0
else:
return sum(args)/float(len(args))
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)==0:
return 0.0
else:
return sum(args)/float(len(args))
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2018-04-07
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for i in d:
print ('%s:%s' % (i,d[i]))
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for i in d:
print ('%s:%s' % (i,d[i]))
2018-04-07
用pc写代码就不存#-*-coding:utf-8 -*-和print u'" ..."'产生冲突的问题了。
2018-04-07
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-04-07
这里的答案并未考虑B的平方减去4ac小于0的情况,修正一下可以是这样:
import math
def quadratic_equation(a, b, c):
A=(b**2-4*a*c)
if A>=0:
t = math.sqrt(A)
return (-b + t) / (2 * a),( -b - t )/ (2 * a)
else:
return
import math
def quadratic_equation(a, b, c):
A=(b**2-4*a*c)
if A>=0:
t = math.sqrt(A)
return (-b + t) / (2 * a),( -b - t )/ (2 * a)
else:
return
2018-04-07
def square_of_sum(L):
return sum(num**2 for num in L)
print (square_of_sum([1, 2, 3, 4, 5]))
print (square_of_sum([-5, 0, 5, 15, 25]))
return sum(num**2 for num in L)
print (square_of_sum([1, 2, 3, 4, 5]))
print (square_of_sum([-5, 0, 5, 15, 25]))
2018-04-07
sum = 0
x = 2
n = 0
while True:
if n>19:
break
sum=sum+x**n
n=n+1
print sum
x = 2
n = 0
while True:
if n>19:
break
sum=sum+x**n
n=n+1
print sum
2018-04-07
import math
def quadratic_equation(a, b, c):
if a==0:
x=-c/b
return x
else:
x1=(-b+math.sqrt(b*b-4*a*c))/2/a
x2=(-b-math.sqrt(b*b-4*a*c))/2/a
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
if a==0:
x=-c/b
return x
else:
x1=(-b+math.sqrt(b*b-4*a*c))/2/a
x2=(-b-math.sqrt(b*b-4*a*c))/2/a
return x1,x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-04-07