我是python的新手,我正在尝试编写一个程序来计算每月投资的未来价值。这是我到目前为止的内容:
var client = algoliasearch(algClient, apiKey);
var index = client.initIndex(algIndex);
var paintingAutocomplete = {
source: autocomplete.sources.hits(index, { hitsPerPage: 4 }),
displayKey: "title",
templates: {
header: '<div class="ad-example-header">Painting</div>',
suggestion: function(suggestion) {
console.log(suggestion);
return (
'<img class="search-thumbnail" src="https://res.cloudinary.com/b3/h_360/' +
suggestion["field_file_name:file"] +
'" />' +
suggestion.title
);
}
}
};
var autocompleteInstance = autocomplete(
document.querySelector("#search-input"),
{
hint: false,
debug: true,
cssClasses: { prefix: 'ad-example'}
},
[
paintingAutocomplete,
]
).on("autocomplete:selected", function(event, suggestion) {
// console.log(suggestion, );
});
var autocompleteChangeEvents = ["selected", "autocompleted"];
autocompleteChangeEvents.forEach(function(eventName) {
autocompleteInstance.on("autocomplete:" + eventName, function(event, suggestion, datasetName) {
// Call the search here...
});
});
search.start();
我的基本布局效果很好。我在数学方面不擅长,有人可以帮我吗?另外,有人可以告诉我当用户不想再继续打印时如何使“再见”打印吗?现在,当您按下n时,它可以回到起点。
答案 0 :(得分:0)
while循环每次循环时都会检查变量choice
。收到用户输入后,您将答案设置为continue_runs
而不是choice
。如果将用户输入改为choice
,则可能会在功能上获得正确的选择。
要计算时间序列付款后的未来价值,您将使用F / A方程。 我发现该网站具有一些常用公式:https://www.me.utexas.edu/~me353/lessons/S2_Evaluation/L02_Equivalence/factor_formulas.html
F = A [(1 + i)^ N-1] / i
您要寻找的是“统一系列复合量因子”。您将使用i作为月利率(年利率)/ 12。 N是总月数。然后,将其乘以A(即每月的缴款)。
答案 1 :(得分:0)
您可以使用break中断循环。我会让你去解决数学问题
#display a welcome message
print("Welcome to the Future Value Calculator\n")
monthly_invest = int(input("Enter monthly investment:\t"))
yearly_interest_rate = float(input("Enter yearly interest rate:\t"))
years = int(input("Enter number of years:\t\t"))
#Yearly values to monthly values
monthly_interest_rate = yearly_interest_rate / 12 / 100
months = years * 12
future_value = 0
for i in range(years):
future_value += monthly_invest
monthly_amount = future_value * monthly_interest_rate
future_value += monthly_amount
print("\nYear = " + str(i+1) + "\t" + "Future value: " + str(round(future_value)))
#Is the loop over?
if i == years-1:
break
#Does the user want to continue?
continue_runs = (input("\nContinue (y/n)? "))
if continue_runs.lower()=='n':
break
print("Bye!")