1

The code below is good (as far as I know), but I thought it may add more context to the bottom half

IncAsk = bool(True)
while IncAsk:
    try:
        Income = {'Jan': int(input("How much money did you make in January? ")),
                  'Feb': int(input("How much money did you make in February? ")),
                  'Mar': int(input("How much money did you make in March? ")),
                  'Apr': int(input("How much money did you make in April? ")),
                  'May': int(input("How much money did you make in April? ")),
                  'Jun': int(input('How much money did you make in June? ')),
                  'Jul': int(input("How much money did you make in July? ")),
                  'Aug': int(input('How much money did you make in August? ')),
                  'Sep': int(input('How much money did you make in September? ')),
                  'Oct': int(input('How much money did you make in October? ')),
                  'Nov': int(input('How much money did you make in November? ')),
                  'Dec': int(input('How much money did you make in December? '))}
    except ValueError:
        print('Oops! It seems you have made a mistake. Numbers only please. Sorry for the inconvenience.')

But this code is were the problem is, it's supposed to check the whole dictionary and see if each individual is a positive number, and if they all are it will print a messasge and move on. If not it will repeat until the user gets it right. But when I run it stops and gives me a 'type error'. Runs fine for the top half just crashes once it reaches this. I have tried multiple diffrent formats for the if statment so I'm pretty sure the problem is somthing deeper, possibly somthing in the top half.

if Income(['Jan'], ['Feb'], ['Mar'], ['Apr'], ['May'], ['Jun'], ['Jul'], ['Aug'], ['Sep'], ['Oct'], ['Nov'], ['Dec']) > -1:
    print('Looks like everything is ok, now on to spending')
    IncAsk = bool(False)
Pink Pit
  • 29
  • 5

1 Answers1

2

Income is not a function, so you can't write Income(...). You access elements with Income[...].

You can't test multiple dictionary elements by putting all the subscripts at once. If you want to test multiple elements, you can use the all() function:

if all(val > -1 for val in Income.values()):

BTW, making the user retype all the inputs when they get any of them wrong seems like poor design. It would be better to check each input as they're entering it, and not go on to the next until they get it right. I suggest you write a separate function for getting an input that meets all the criteria, and call that when assigning to the dictionary.

Barmar
  • 741,623
  • 53
  • 500
  • 612