一些最简单的代码:
# A function lesson
# the use of the key word:def
print "Welcome to Python!"
#now we begin to def a function
#first ,we give a list of integers:
cast1 = [1,2,3,4,5,6,7,8,9,10]
cast2 = [10,120,21303,3214,34,3254,667]
print cast1
print "the len of the cast1:"
print len(cast1)
print "the len of the cast2:"
print len(cast2)
#ok now ,we can def a function to get the sum of the list:
def ask_sum(casts,n):
cnt=0
i=0
#print cnt
while i<n-1:
#This place I can't use the for_loop ,and I don't know why it shouldn't be!!!
#print(i)
cnt=cnt+casts[i]
i=i+1
print cnt
#and you know,the python allow the programer to digui(I have to use a Chinese here !!! smiling)
#but the depth ought to be less than 100 in Python3
ask_sum(cast1,len(cast1))
ask_sum(cast2,len(cast2))