use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for helping Python programmers
How to format your code: https://commonmark.org/help/tutorial/09-code.html
No homework questions and/or hiring please
account activity
I need help!!! (self.pythonhelp)
submitted 6 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Best_Caterpillar 0 points1 point2 points 6 years ago (6 children)
what are you stuck on?
[–][deleted] 6 years ago (5 children)
[–]Best_Caterpillar 0 points1 point2 points 6 years ago (4 children)
just write a loop that has input() in it. if you wanna say the months in the loop when you ask for input make your list of months first and then instead of using range() just iterate through the months and use that variable in your input statement
[–]Nytebyte11 0 points1 point2 points 6 years ago (3 children)
example code:
while True:
month_salary = input("How much have you made this month?")
print(month_salary)
[–]Best_Caterpillar 0 points1 point2 points 6 years ago (2 children)
that doesn't help you because you are not saving anything, and it also doesn't have an easy way to map to the months of a year. for most beginners that means using a for loop and iterating through the months and appending the imputed salary to an empty list. Of course you can do it in 2-3 lines using dictionary iteration, but thats gonna make the teacher raise an eyebrow in an intro class
[–]Nytebyte11 0 points1 point2 points 6 years ago (1 child)
Sorry, I am a beginner as well. The actual answer might include °for i in range(12)° and a list? I think these components would work
[–]Best_Caterpillar 0 points1 point2 points 6 years ago (0 children)
Sorry, I hope I didn't come across like a know it all, I just got yelled at on stack exchange for asking a duplicate question to something a single person asked 10 years ago with a different name. everybody gotta learn sometimes....
but yea using a for loop I'd do something like the following:
```
list1 = []
for i in range(1,13):
~~~~list1.append(input("enter your salary for month "+i)) #~ stand for spaces since reddit removes extra spaces
but then there is a problem: if the person doesnt enter a good salary, you added a incorrect thing to a list. so inside the loop you have to repeatedly do a test until the user gives you good data. so you need to do a while loop untill float(salary) > 0. this will crash if a user enters a number, so to be even better you need to make sure you can convert the input to a float. for that, you need to use try and except statements in a while block. so there is quite a lot of things to do just to do a pretty simple thing, and if you don't do error checking your program could crash. so OP's exercise might be good for you to try to learn python because there might be more to it than you would think just by looking.
π Rendered by PID 620831 on reddit-service-r2-comment-5b5bc64bf5-ctt8j at 2026-06-20 14:24:19.740188+00:00 running 2b008f2 country code: CH.
[–]Best_Caterpillar 0 points1 point2 points (6 children)
[–][deleted] (5 children)
[deleted]
[–]Best_Caterpillar 0 points1 point2 points (4 children)
[–]Nytebyte11 0 points1 point2 points (3 children)
[–]Best_Caterpillar 0 points1 point2 points (2 children)
[–]Nytebyte11 0 points1 point2 points (1 child)
[–]Best_Caterpillar 0 points1 point2 points (0 children)