我正在尝试制作一个简单的复合和年度投资计算器,但是有一个我无法发现的错误。我是否错过了for或while循环?
var sourceService = new Stripe.StripeSourceService();
// Get customer with current payment source.
var stripeCustomer = customerService.Get(stripeCustomerWithAccount.Id, new Stripe.StripeRequestOptions { ApiKey = ConfigurationManager.AppSettings["StripeSecretKey"] });
// Set Stripe Customer Id and Stripe Token options.
var tokenService = new Stripe.StripeTokenService();
var stripeToken = tokenService.Get(tokenId, new Stripe.StripeRequestOptions { ApiKey = ConfigurationManager.AppSettings["StripeSecretKey"] });
// Check if credit card already exists.
if (!CreditCardExists(stripeCustomer, stripeToken))
{
// Create new credit card.
var sourceOptions = new StripeNet.StripeSourceCreateOptions()
{
Customer = stripeCustomer.Id,
Card = new StripeNet.StripeCreditCardOptions
{
TokenId = stripeToken.StripeCard.Id
}
};
var source = sourceService.Create(sourceOptions, new Stripe.StripeRequestOptions { ApiKey = ConfigurationManager.AppSettings["StripeSecretKey"] });
}
答案 0 :(得分:1)
print("Investment Calculator")
print(f"=====================")
present_value = int(input("Principal Amount? "))
interest_rate = float(input("Annual Interest Rate? "))
terms_in_years = int(input("Number of Years? "))
future_value = present_value * pow((1 + (interest_rate / 100)), terms_in_years)
result = float("{:.2f}".format(future_value))
print(f"Future Value is: {result}")"
答案 1 :(得分:0)
数字对我来说看起来很好。(1000
+ .01
+ 10
):
def formatInterest(t):
return "{:>3} {:<10}".format(t[0],round(t[1],2))
investment=float(input("Enter an initial investment."))
interest=float(input("Enter an interest rate between .01 to .10."))
years=int(input("Enter a number of years between 1 to 30."))
print(*list(map(formatInterest,enumerate([investment * (interest+1) ** i
for i in range(years+1)]))),sep="\n")
输出:
0 1000.0
1 1010.0
2 1020.1
3 1030.3
4 1040.6
5 1051.01
6 1061.52
7 1072.14
8 1082.86
9 1093.69
10 1104.62
您可以在此处了解有关map(),enumerate()和print()的信息:
列表推导产生每年的值,从0到10(输入)开始。 enumerate
添加formatInterest
-input-tuple的年份。 map
应用格式,print()
使用所有已分解列表上的换行符sep
将其全部打印出来。