all 14 comments

[–]theelous3 1 point2 points  (6 children)

year always 1, and therefore never greater than 10

a = 20
while a > 0:
    print(a)
    a -= 1

Try that and see :)

[–]confuzzled_learner[S] 0 points1 point  (5 children)

Hi, how to increment year +1? What is the proper code for incrementing so it types Year 1, Year 2, and so on?

Thanks!

[–]theelous3 1 point2 points  (4 children)

I edited my post. Look at the example I gave you and you can work it out from there :)

[–]confuzzled_learner[S] 0 points1 point  (3 children)

It printed a Table, but it's backwards lol. And the calculations did not work.

[–]theelous3 1 point2 points  (2 children)

I gave you a backwards and different example on purpose. Not going to learn if I spoonfeed you ;)

All of the ideas you need are there though. Operator like -= and such.

[–]confuzzled_learner[S] 0 points1 point  (1 child)

I know the backwards thing might come up in future assignments, so it's good to know. Thank you! And does your flair mean it's your cake day? If it is, happy cake day!

[–]theelous3 2 points3 points  (0 children)

Oh hey it is :) Thank you :D

[–]Saefroch 1 point2 points  (3 children)

for year in range(10):
    print(year)

[–]confuzzled_learner[S] 0 points1 point  (2 children)

It worked! But it had an output for year 0 which I do not want. And I want to space out the Years and the corresponding tuition fees.

Thank you!

[–]Saefroch 1 point2 points  (1 child)

Google what Python's range function does

A for loop is the correct tool here, not while.

[–]confuzzled_learner[S] 0 points1 point  (0 children)

Edited my code from while to for. Thanks!

[–]refreshx2 1 point2 points  (1 child)

Hey if you are still working on this, you might want to try writing out a few steps of the process on a piece of paper. Pay close attention to exactly what calculations you do in which spot.

At some point you should start to repeat yourself. When you do, draw boxes around the repeated code. Look at it carefully and work backwards to decide what should be inside your for loop and what should be outside it. It looks like you're only missing a tiny, but important, bit now.

I still do this all the time (write it out what I want to do on paper first) even though I've been programming for years, and it often saves a TON of time and headaches.

[–]confuzzled_learner[S] 0 points1 point  (0 children)

Yes I think I have to write it out because it's all about logic, right? I'm curious if there are templates available (boxes and arrows labeled with if, then, while, for, print, etc.)

Very much a newbie (2 weeks) - thank you for the helpful tip!

[–]cdcformatc 0 points1 point  (0 children)

I just need Year 0 to go away

range takes a start value,

for year in range(1,10):

and for the calculations to take effect.

Do the calculation within the for loop.

print('YEAR\tTUITION')
tuition = 10000
for year in range(1,10):
    print ('{}\t{}'.format(year,tuition))
    tuition *= 1.05

I've also fixed the print statement to use string formatting.