Python学习(4)

一些最简单的代码:

# 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))


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值