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
2019-02-27
将一个函数的一个或多个参数添加默认参数,只需要在原参数后添加“=(默认值)”即可,并在函数中将默认情况考虑进去,在必要的时候进行更改即可。
2019-02-26
函数名有问题,square of sum是和的平方,sum of square才是平方和,既然想用英文来命名函数,就用正确,麻烦改一下
2019-02-26
print 'hello,python'
print 'hello'+','+'python'
print 'hello'+','+'python'
2019-02-25
print 45678+0x12fd2
print "Leran Python in imooc"
print 100<99
print 0xff==255
print "Leran Python in imooc"
print 100<99
print 0xff==255
2019-02-25
试了试,别的方法。
def p(n):
if n==1:
return 1
else:
return p(n-1)+(n-1)*3+1
print(p(100))
def p(n):
if n==1:
return 1
else:
return p(n-1)+(n-1)*3+1
print(p(100))
2019-02-25
我理解错了,我以为要完全打出来这样的形式,包括\ ' "的,
'\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.'
'\"To be, or not to be\": that is the question.\nWhether it\'s nobler in the mind to suffer.'
2019-02-25
最方便的办法就是用列表生成式,但还没讲到啊
L = [x*x for x in range(1,101)]
print sum(L)
L = [x*x for x in range(1,101)]
print sum(L)
2019-02-24
我试着a=”中文“,比如a='神经刀’,直接提交后提示错误,后来在首行加入了“# -*- coding: utf-8 -*-”,才通过了。
2019-02-23
import math
def quadratic_equation(a, b, c):
sqrt_num = b ** 2 - 4 * a * c
x1 = (-b + math.sqrt(sqrt_num)) / (2 * a)
x2 = (-b - math.sqrt(sqrt_num)) / (2 * a)
return x1, x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
def quadratic_equation(a, b, c):
sqrt_num = b ** 2 - 4 * a * c
x1 = (-b + math.sqrt(sqrt_num)) / (2 * a)
x2 = (-b - math.sqrt(sqrt_num)) / (2 * a)
return x1, x2
print quadratic_equation(2, 3, 0)
print quadratic_equation(1, -6, 5)
2019-02-22
#coding=utf:8
def square_of_sum(L):
sum_list = 0
for i in L:
x = i ** 2
sum_list += x
return sum_list
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
def square_of_sum(L):
sum_list = 0
for i in L:
x = i ** 2
sum_list += x
return sum_list
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2019-02-22