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

dkjs1.py

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

# 等额本息 每月还款额计算公式如下:
# =(贷款本金*月利率*(1+月利率)^还款月数)/((1+月利率)^还款月数-1)
def compute():
    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)
        txt = "每月还款额: %.2f元\n还款总利息= %.2f元\n" % (mhk,total-c)
        droid.fullSetProperty("Text2","text",txt)
    except:
        droid.makeToast(‘Error: 输入数字有错误‘)
        return

def eventloop():
  while True:
    event=droid.eventWait().result
    if event["name"]=="click":
      id=event["data"]["id"]
      if id=="compute":
        compute()
      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/compute"
            android:layout_width="140dip"
            android:layout_height="wrap_content"
            android:text="等额本息计算"
            />
        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="年利率"
            android:inputType="textPhonetic|number">
            <requestFocus></requestFocus>
        </EditText>
  </LinearLayout>
  <LinearLayout android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
        <EditText
            android:id="@+id/editText2"
            android:layout_width="200dp"
            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

python for android : 贷款等额本息每月还款额计算,布布扣,bubuko.com

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

上一篇:鼠标滚轮滑动滚动div


下一篇:手机号段验证