浙江大学pta答案python函数题_PTA的Python练习题(十五)

第4章-12 求满足条件的斐波那契数

a=eval(input())

b=c=1

d=1

for i in range(a):

c=b

b=d

d=b+c

if d>a:

print('{}'.format(d))

break

第4章-13 求误差小于输入值的e的近似值

a=eval(input())

b=1

count=1

count2=0

for i in range(1,100000):

b=b*i

count2=count

count=count+1/b

if (count-count2)

print('{:6f}'.format(count))

break

第4章-14 统计字符

参考了别人的代码:

s=[]

count=0;letters=0;space=0;digit=0;others=0

while True:

b=list(input())

count=count+1

s.extend(b)

if len(s)+count>10:

count=count-1

break

for c in s:

if c.isalpha():

letters+=1

elif c.isspace():

space+=1

elif c.isdigit():

digit+=1

else:

others+=1

print('letter = {}, blank = {}, digit = {}, other = {}'.format(letters,space+count,digit,others))

用列表输入,用count算回车数,如果合计大于10就退出循环,下面调用python自带函数计算

标签:练习题,count,digit,letters,space,Python,PTA,others,input

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值