作业

字母排序

s = ‘bfzajciot’ #raw_input(‘input = ‘)
x = s[0]
y = s[0]
n = 0
for i in s:
if n+1 < len(s):
if i <= s[n+1]:
x += s[n+1]
else:
if len(x)>len(y):
y = x
x = s[n+1]
else:
x = s[n+1]
n += 1
else:
break
if len(x) > len(y):
y = x
print ‘Longest substring in alphabetical \
order is:’,y

Using bisection search to make the program faster

balance =  999999
annualInterestRate =  0.18

b = balance
MonthlyInterestRate = annualInterestRate/12.0
lower = balance/12.0
upper = (balance * (1+MonthlyInterestRate)**12) / 12.0
pay = (lower + upper)/2

n=0
i=0
while True:
    balance = b
    for x in range(1,13):
        UpdatedBalanceEachMonth= (balance-pay) *(1+ MonthlyInterestRate)
        balance = UpdatedBalanceEachMonth

    print 'balance=',balance,'pay=',pay
    if balance < -0.02:
        upper = pay
        pay = lower +(upper - lower)/2
    elif balance > 0.02:
        lower = pay
        pay = pay +(upper - lower)/2
    else:
        break
    n+=1
print 'Lowest Payment:%.2f'%pay
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值