python for android : 贷款每月还款额计算

功能: 1.等额本息 每月还款额计算 

2.等额本金 每月还款额计算

dkjs3.py

# -*- coding: utf-8 -*-
import android
import os,sys
reload(sys)
sys.setdefaultencoding('utf-8')
droid = android.Android()

# 等额本息 每月还款额计算公式如下:
# =(贷款本金*月利率*(1+月利率)^还款月数)/((1+月利率)^还款月数-1)
def compute1():
    rate= droid.fullQueryDetail("editText1").result["text"]
    cap = droid.fullQueryDetail("editText2").result["text"]
    months= droid.fullQueryDetail("editText3").result["text"]
    print rate,cap,months
    try:
        c = float(cap)
        r = float(rate)
        m = float(months)
        if m >360.0: return
        mhk = (c*(r/1200)*(1+r/1200)**m)/((1+r/1200)**m-1)
        total = mhk*m
        print 'total: %.2f' % (total)
        out = "每月还款额: %.2f元\n还款总利息= %.2f元\n" % (mhk,total-c)
        droid.fullSetProperty("Text2","text",out)
    except:
        droid.makeToast('Error: 输入数字有错误')
        return

# 等额本金 每月还款额计算公式如下:
# 每月本金 = 贷款本金/总月数
def compute2():
    rate= droid.fullQueryDetail("editText1").result["text"]
    cap = droid.fullQueryDetail("editText2").result["text"]
    months= droid.fullQueryDetail("editText3").result["text"]
    print rate,cap,months
    try:
        c = float(cap)
        r = float(rate)
        m = int(months)
        if m >360: return
        cm = c/m
        out = '每月本金: %.2f元\n期数 每月利息 每月还款额\n' % (cm)
        total =0.0
        for i in range(0,m):
            mint = (c-cm*i)*r/1200
            total += mint
            out += '%2d期: %.2f元 %.2f元\n' % (i+1,mint,cm+mint)
        out += '还款总利息= %.2f元\n' % ((m+1)*c*r/1200/2)        
        droid.fullSetProperty("Text2","text",out)
        print 'total: %.2f' % (c+total)
    except:
        droid.makeToast('Error: 输入数字有错误')
        return

def eventloop():
  while True:
    event=droid.eventWait().result
    if event["name"]=="click":
      id=event["data"]["id"]
      if id=="button1":
        compute1()
      if id=="button2":
        compute2()
      if id=="Exit":
        return
    elif event["name"]=="screen":
      if event["data"]=="destroy":
        return

layout = """<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/background"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent" android:background="#ff000000">
  <LinearLayout android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
        <Button
            android:id="@+id/Exit"
            android:layout_width="60dip"
            android:layout_height="wrap_content"
            android:text="退出"
            />
        <Button
            android:id="@+id/button1"
            android:layout_width="120dip"
            android:layout_height="wrap_content"
            android:text="等额本息计算"
            />
        <Button
            android:id="@+id/button2"
            android:layout_width="120dip"
            android:layout_height="wrap_content"
            android:text="等额本金计算"
            />
  </LinearLayout>
  
  <LinearLayout android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
        <EditText
            android:id="@+id/editText1"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:hint="年利率"
            android:inputType="textPhonetic|number">
            <requestFocus></requestFocus>
        </EditText>
        <EditText
            android:id="@+id/editText2"
            android:layout_width="160dp"
            android:layout_height="wrap_content"
            android:hint="贷款本金"
            android:inputType="number">
            
        </EditText>
        <EditText
            android:id="@+id/editText3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="月数"
            android:inputType="number">
            
        </EditText>
  </LinearLayout>
    
    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical" 
        android:fadingEdge="vertical" >
    <TextView
        android:id="@+id/Text2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:singleLine="false"
        android:textSize="16"
        android:textColor="#004000"
        android:background="#FFFFF0"
        android:padding="10dip"
        android:hint="输出"
        />
    </ScrollView>
</LinearLayout>
"""

droid.fullShow(layout)
eventloop()
droid.fullDismiss()


参考 https://code.google.com/p/android-scripting/wiki/FullScreenUI


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值