python的初级训练

读了一点《A Byte Of Python》,对python有了初步的认识,但是没有动手练练总是不行的。所以在zoj上找了几道简单题用python写一写:
zoj 1001 A+B Problem

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1001
大意就是输出两个数的和。

import sys
for line in sys.stdin:
    a=line.split()
    print int(a[0])+int(a[1])
zoj 1048 Financial Management

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=48
简单的说就是输出平均数。

#import sys
#sys.stdin=open('d:\\in.txt','r')  绝对路径输入输出
#sys.stdout=open('d:\\out.txt','w')
#sys.stdin=open('in.txt','r')  相对路径输入输出
#sys.stdout=open('out.txt','w')
sum=0
for line in range(0,12):
    month=raw_input()
    sum+=float(month)
print('$%.2f'%(sum*1.0/12))
zoj 1049 I Think I Need a Houseboat

题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=49

大意:每行给出两个数代表自己的坐标,从原点开始侵蚀面积(一个半圆)每一年都会增长50 m^2,问第几年自己的位置会被侵蚀。

#import sys
import math
n=int(raw_input())
for i in range(0,n):
    line=raw_input()
    lr=line.split()
    a=float(lr[0])
    b=float(lr[1])
    r_2=a*a+b*b
    s2=math.pi*r_2/2
    s1=50
    while(s1<s2):
        s1+=50
    print('Property %d: This property will begin eroding in year %d.'%(i+1,s1/50))

print('END OF OUTPUT.')
话说回来,代码里没有使用的sys也算compilation error,太严肃了吧。。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值