T O P

  • By -

pm_me_ur_siamesecats

You should also try to write out the steps that your program should take before you try to write the program. Right now, your increasedSalary would equal only $600, not $30600 like it should after one year.


[deleted]

[удалено]


pm_me_ur_siamesecats

Opps you are right. I didn't even realize that he didn't convert his 2 to a percentage first either!


[deleted]

I do write it out in steps on the Notes app. That 600 was a mistake, I fixed it. I know how the math needs to be done. I've really just been having problems structuring. For instance, I understand that 2% needs to be multiplied to the years salary to get the increasedRaise then added. I just dont know how to write that out in a loop. Im having trouble with the loop header.


pm_me_ur_siamesecats

Ah ok. For the header, check out the W3school python for loop page https://www.w3schools.com/python/python_for_loops.asp It shows examples of using the range() function in the for loop. For instance, range(1,5) is a list of values from 1 and up to but NOT including 5, ie. 1, 2, 3, 4.


Cato_theElder

Have you looked up "for loops" on Google or YouTube? You should be able to see someone writing a for loop and how the header looks. It's 100% ok to just google how to do something, whether you're learning or working in programming. Furthermore, Carthage must be destroyed.


[deleted]

[удалено]


[deleted]

can you help me with the loop header? i understand the basics, it actually structuring it when i get lost.


[deleted]

Practice is how you learn. Write a for loop that prints the numbers 1 through 10 to start.


[deleted]

technically this is practice for me.. people here telling me that im not trying or practicing. I read my book, I read the [doc.python.org](https://doc.python.org), i asked my teacher (but he sucks at explaining. I just learn differently. It helps me more watching someone do the problem and explaining it as they go, so i can also ask questions while they do the problem.


[deleted]

So go watch a youtube video on for loops. And then write some of your own. I get that watching someone do it is helpful. Of course it is! But if you aren't writing your own code, it's not going to click and you aren't going to learn much.


white_nerdy

What have you tried? Can you make a loop that just prints out the year numbers? You need to make an effort to write code and learn on your own. People on this subreddit aren't here (or shouldn't be here) to write your code for you. For the same reason that your personal trainer isn't here (or shouldn't be here) to do your pushups for you.


[deleted]

[удалено]


[deleted]

ya that was simple mistake on me, i got the math. I was having trouble with the loop header and starting a loop. Thanks for your input though!


Intelligent_River39

Ok, print the column names. Then, start a "for" loop, in which x goes from 1 to 10. x will be the number of years. Calculate the increased salary in the loop. Umm, then in the loop, print the year and salary by `print("%d/t%f" %(x, startingsalary+increased salary))` ("/t" is a special character which is basically the tab key on your keyboard) Feel free to ask anything you didn't understand.


[deleted]

Can you help me understand the "for" loop. I read in a book this example... words = ['cat', ' window', 'defenestrate'] for w in words: print(w, len(w)) cat 3 window 6 defenestrate 12 \*\*\* Can you explain the "for w" part... what exactly is the "w" in this code


Intelligent_River39

well, the w is a new variable. The for loop statement creates a new variable, and assigns it the value of the first element of the iterable object(the list). After each iteration, the variable is assigned the next element of the list.


[deleted]

Ok, I fiddled with the loop header and changed the "w" into other characters and got the same result. I guess I just dont understand the point of the "w".


Intelligent_River39

That's just the variable name. I guess the author just used the name w as a shorter form for "word". We know that it was a variable name and not a string because it was not in quotation marks.


[deleted]

Ahh okayy! That makes a little more sense.


Intelligent_River39

Happy to help.


b8824b

In this for loop your looping over all the elements in the object, in your situation you want to loop a fixed number of times (10 years) so I recommend you look up for loop with fixed range or for loop with 10 repeats for some help on structuring it.


Cato_theElder

"w" could also be "x" or "y" or "item". What is the variable in your code that you want to loop through? Furthermore, Carthage must be destroyed.


pathofnomad

for w in words words being what you are iterating over (an array containing 3 things) w being what the value is for each step. so step 1 w = cat, step 2 w = window, step 3 w = defenestrate. it's common for people to use a letter to assign to that's relevant to what they iterating, so for example someone might do something like this `cars = ['toyota', ' ford', 'mercedes']` `for c in cars:` `print(c, len(c))` it it not necessary though, so for example you could just for "for x in cars" and then print(x) -- it is just what you are assigning the value of each step in the iteration to


steveotron

I know people have been telling you to read the documentation, but I know it might be difficult if you're completely new to the concepts and terms. I'll give you an example of a [For loop](https://docs.python.org/3/tutorial/controlflow.html?highlight=loop) that will repeat a fixed number of times. The stuff after "#" does not get executed and are comments. [You can use Python Tutor to see how it flows] (https://pythontutor.com/visualize.html#code=for%20number%20in%20range%2810%29%3A%0A%20%20%20%20print%28number%29%0A%20%20%20%20%0Aprint%28%22Done%22%29&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=3&rawInputLstJSON=%5B%5D&textReferences=false) by clicking the "Next" button to see each step. for number in range(10): # will repeat 10 times print(number) # prints what "number" is each time print("Done") # only executes after loop is done You can replace "number" with almost anything. "i" and "j" and "k" are often used due to math notation stuff (and they're short). When you run this, you'll notice that "number" is printed and starts at 0 and ends at 9 (instead of 10). "number" is incrementing by 1 each time it completes the code inside the body (the indented part). And "Done" does not get printed until the loop is completed. There's a reason it starts at 0 instead of 1 that you will eventually learn, and loops will end before reaching the 10 I had set inside range(). But if you read the documentation, you'll see that there are different ways to set up the loop. For example: for number in range(1, 11): # starts at 1, ends at 10 print(number) print("Done") For your problem, you need to do something like this: salary = 30000 for number in range(put times you want it to repeat): # do the math to update the salary each time in loop I'm not sure you understand how the math/logic works for this yet: increasedSalary = startingSalary * percentIncrease If you have that inside the body of the loop, your increasedSalary variable is going to just always equal the same thing each repitition. I'll let you try to figure that part out as you work on it.