核心编程第五章

#5-5
def swit(mon):    
    cent = [25,10,5,1]
    n=[]
    y=mon*100
    for i in cent:
        x,y = divmod(y,i)
        n.append(int(x))
    print n
    
swit(input("dollar"))


#5-6
def calculater():
    a=raw_input(">")

    for i in ['**','+','-','*','/','%']:
        if i in a:
            x=a.split(i)
            break

    for j in range(2):
        if '.' in x[j]:
            x[j]=float(x[j])
        else:
            x[j]=int(x[j])

    dict={'+':x[0]+x[1],'-':x[0]-x[1],'*':x[0]*x[1],
          '/':x[0]/x[1],'**':x[0]**x[1],'%':x[0]%x[1]}
    return dict[i]

print calculater()

#5-13
def Timeconvert():
    time=raw_input("the time is:")
    a=time.split(':')
    ntime=int(a[0])*60+int(a[1])
    return ntime
print Timeconvert()

#5-15
def Twoints():
    m=a1=int(raw_input("The first number:"))
    n=a2=int(raw_input("The second number:"))
    while True:
        a1,a2=a2,a1%a2
        if a2==0:
            print "most is:", a1
            print "least is:", m*n/a1
            break
Twoints()

#5-16
sum=float(raw_input("Enter opening balance:"))
pay=float(raw_input("Enter monthly payment:"))
print "   Amount  Remaining"
print "Pymt#  Paid      Balance"
print "-----  ------    -------"
n=0
print "0      $ 0.00    $100.00"
while sum>=pay:
    n+=1
    sum-=pay
    print "%d      $%5.2f    $%6.2f" % (n,pay,sum)
print "%d      $%.2f     $%6.2f" % (n+1,sum,0)


转载于:https://my.oschina.net/u/2519674/blog/651623

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值