zoukankan      html  css  js  c++  java
  • 《python语言程序设计》_第二章笔记之2.13_软件开发流程

    #程序1:

    设计:由用户键入利率、贷款数以及贷款的年限,系统计算出每月还贷数和总还款数

    注意:输入的年利率是带有百分比的数字,例如:4.5%。程序需要将它除以100转换成小数。因为一年有12个月,所以将年利率除以12即是月利率,为了获得月利率,月利率=年利率/(12+100)

    程序:

    annualInterestRate =eval(input("Enter annual interest rate,e.g., 7.25:"))
    #输入年度利率
    monthlyInterestRate=annualInterestRate / 1200
    # 月利率=年利率/1200
    numberOfYears = eval(input("Enter number of years as an integer,e.g.,5:"))
    #输入贷款年限
    loanAmount=eval(input("Enter loa amount,e.g.,120000.90:"))
    #输入贷款数目
    monthlyPayment =loanAmount * monthlyInterestRate/(1-1/(1+monthlyInterestRate)**(numberOfYears*12))
    #定义月供(月还款数)
    totalPayment=monthlyPayment*numberOfYears*12 #定义年付款额
    print("The monthly payment is",int(monthlyPayment*100)/100)
    print("THE total payment is",int(totalPayment*100)/100)
    #先乘以100取整再除以100,是为了保留小数点后的两位。

    结果:


    Enter annual interest rate,e.g., 7.25:5.75

    Enter number of years as an integer,e.g.,5:15

    Enter loa amount,e.g.,120000.90:250000
    The monthly payment is 2076.02
    THE total payment is 373684.53

     程序2:计算距离(两点之间的距离最近)

     程序:

    x1,y1=eval(input("Enter x1 and y1 for point1:"))
    #输入第一个点的坐标x1,y1
    x2,y2=eval(input("Enter x2 and y2 for point2:"))
    #输入第二个点的坐标
    distance =((x1-x2)**2+(y1-y2)**2)**0.5
    #定义距离公式
    print("The distance between the points is" , distance)

    结果:

    Enter x1 and y1 for point1:1.5,-3.4

    Enter x2 and y2 for point2:4,5
    The distance between the points is 8.764131445842194

  • 相关阅读:
    POJ 1182 食物链(带权并查集)
    UVa 10655 n次方之和(矩阵快速幂)
    2016湘潭邀请赛—Heartstone
    2016湘潭邀请赛—Gambling
    UVa 10375 选择与除法(唯一分解定理)
    UVa 1637 纸牌游戏(全概率公式)
    POJ 2443 Set Operation(压位加速)
    UVa 11248 网络扩容(最大流(需要优化))
    51Nod 1737 配对(树的重心)
    51Nod 1070 Bash游戏 V4(斐波那契博弈)
  • 原文地址:https://www.cnblogs.com/qiyuanjiejie/p/9551142.html
Copyright © 2011-2022 走看看