基于第一个开始第二个循环

时间:2016-10-14 15:38:49

标签: python for-loop nested nested-loops

我正在尝试编写一个能够计算学费未来价值的课程。今天的学费是10000美元,每年增加5%。我正在努力编写一个程序,告诉我10年级的学费,以及10-13年的总学费。

我几乎可以肯定,我正在编写2 for for循环,但我的程序将无法运行。

def callit(tups, char):
    result = ''
    for tup in tups:
        result += dostuff(tup[0], tup[1], char) + '\n'
    result = result[:result.rfind('\n')] # trim off the last \n
    return result

有人有任何建议吗?

2 个答案:

答案 0 :(得分:0)

试试这个:

import {Component, OnInit, OnDestroy} from '@angular/core';
import {Router} from '@angular/router';
import {Subscription} from 'rxjs';

@Component({
  template: `...`
})
export class FolderViewerComponent implements OnInit, OnDestroy {

  url: string;
  routeSub: Subscription;

  constructor(private router: Router) {
  }

  handleRouteChange(event) {
    if (this.url !== event.url) {
      this.url = event.url;
      console.log(`Route changed to ${this.url}`);
      // Whatever code you want
    }
  }

  ngOnInit() {
    this.routeSub = this.router.events.subscribe(this.handleRouteChange);
  }

  ngOnDestroy() {
    this.routeSub.unsubscribe();
  }
}

答案 1 :(得分:0)

我认为,你的程序应该是这样的:

tuition_cost = 10000
increase = 1.05
running_total = 0

for year in range(0, 11):
    price_for_year = tuition_cost*(increase**year)
    print(price_for_year)

for year in range(10, 14):
    running_total += price_for_year
    price_for_year = tuition_cost*(increase**year)
    print(running_total)
相关问题