PTA的Python练习题(十三)

第4章-8 求分数序列前N项和

a=eval(input())
b=2
c=1
d=0
count=0
for i in range(a):
    count+=b/c
    d=b
    b=b+c
    c=d
print('%.2f'%(count))

第4章-9 查询水果价格

print('[1] apple')
print('[2] pear')
print('[3] orange')
print('[4] grape')
print('[0] exit')
a=input()
a=a.split()
count=0
for i in a:
      if count ==5 or i=='0':
          break
      if i<'0' or i>'5':
          print('price = 0.00')
      if i=='1':
          print('price = 3.00')
          count=count+1
      if i == '2':
          print('price = 2.50')
          count = count + 1
      if i == '3':
          print('price = 4.10')
          count = count + 1
      if i == '4':
          print('price = 10.20')
          count = count + 1

猜你喜欢

转载自www.cnblogs.com/echoDetected/p/12330689.html