2016-12-07 2 views
-4

私は以下を持っています。100で割るべき利息の値を返すべきです。私は金利を10進数値に変換する必要があります

import math 

p = int(raw_input("Please enter deposit amount: \n")) 
r = float(raw_input("Please input interest rate: \n")) /100 
t = int(raw_input("Please insert number of years of the investment: \n")) 
interest = raw_input("Do you want a simple or compound interest ? \n") 

A = p*(1+r*t) 
B = p*(1+r)^t 

if interest == "simple": 
print (float(A)) 
else: 
print(float(B)) 
+0

それを試してみてください? – Iluvatar

+4

ビットのXOR: 'B = p *(1 + r)** t'である'^'ではなく、' ** 'Pythonの指数演算子を使うべきであることに注意してください。 –

+1

あなたは何に問題がありますか? – Qwerty

答えて

1

(あなたはこのような何かのためにimport mathする必要はありませんヒント)このような何かを試してみてください:

from decimal import * 

p = Decimal(raw_input("Please enter deposit amount:")) 
r = Decimal(raw_input("Please input interest rate as a percentage:")) /100 
t = int(raw_input("Please insert number of years of the investment:")) 
n = 1 # You should really be asking how many times is the interest compounded per year? If the user chooses compound... 

A = p*(1 + r)**t 
B = p*(1 + r)**(n*t) 

while(True): 
    interest = raw_input("Do you want simple or compound interest?") 
    if(interest.lower() == "simple"): 
    print(A) 
    break 
    elif(interest.lower() == "compound"): 
    print(B) 
    break 

あなたは `A/100`を意味する何を、here!

関連する問題