sum = 0
x = 1
while x<100:
if x%2==1:
sum=sum+x
print 'sum=',sum
x=x+1
print 'x=',x
print sum
初学者看这个的运行结果很容易理解
x = 1
while x<100:
if x%2==1:
sum=sum+x
print 'sum=',sum
x=x+1
print 'x=',x
print sum
初学者看这个的运行结果很容易理解
2018-09-01
import math
def quadratic_equation(a, b, c):
t=math.sqrt(b*b-4*a*c)
return (t-b)/(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*b-4*a*c)
return (t-b)/(2*a),(-b-t)/(2*a)
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2018-08-30
def square_of_sum(L):
sum=0
for x in L:
sum=sum+(x*x)
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
sum=0
for x in L:
sum=sum+(x*x)
return sum
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-08-30
# and运算:
# a and b,只要a为true,无论b是什么,返回b;
# a and b,如果a为false,结束and运算,返回a;
# or运算:
# a or b,只要a为true,结束or运算,返回a;
# a or b,如果a为false,无论b是什么,返回b;
# a and b,只要a为true,无论b是什么,返回b;
# a and b,如果a为false,结束and运算,返回a;
# or运算:
# a or b,只要a为true,结束or运算,返回a;
# a or b,如果a为false,无论b是什么,返回b;
2018-08-29
print 'hello,', 'python' 这个语句输出的话“,”后面不就有空格了?
2018-08-29