第二周测试题目

1.假设你每年初往银行账户中1000元钱,银行的年利率为4.7%。

一年后,你的账户余额为:

1000 * ( 1 + 0.047) = 1047 元

第二年初你又存入1000元,则两年后账户余额为:

(1047 + 1000) * ( 1 + 0.047) = 2143.209 元

以此类推,第10年年末,你的账户上有多少余额?

注:结果保留2位小数(四舍五入)。  12986.11

1 total = 0
2 for x in xrange(0,10):
3     total = (total+1000)*(1+0.047)
4 print total

2.对于一元二次方程,若有 ,则其解是什么?若有多个解,则按照从小到大的顺序在一行中输出,中间使用空格分隔。解保留2位小数(四舍五入)。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import math
def quadratic(a,b,c):
    if a == 0:
        raise TypeError('a不能为0')
    if not isinstance(a,(int,float)) or  not isinstance(b,(int,float)) or not isinstance(c,(int,float)):
        raise TypeError('Bad operand type')
    delta = math.pow(b,2) - 4*a*c
    if delta < 0:
        return '无实根'
    x1= (math.sqrt(delta)-b)/(2*a)
    x2=-(math.sqrt(delta)+b)/(2*a)
    return x1,x2
print(quadratic(10,40,15))
原文地址:https://www.cnblogs.com/reese0329/p/7041263.html