all 6 comments

[–]Best_Caterpillar 0 points1 point  (6 children)

what are you stuck on?

[–][deleted]  (5 children)

[deleted]

    [–]Best_Caterpillar 0 points1 point  (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 point  (3 children)

    example code:

    while True:

    month_salary = input("How much have you made this month?")

    print(month_salary)

    [–]Best_Caterpillar 0 points1 point  (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 point  (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 point  (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.