-1

my code is generating a TypeError that it cannot unpack non-iterable integer objects

BMI = {
  15: 'underweight',
  23: 'normal weight',
  24: 'normal weight'
  }

with open('output.txt', 'w') as out:
  for k,v in BMI:
    out.write('%s : %s \n' %(k, v))

My desirable output in a text file would look like this:

15: underweight
23: normal weight
24: normal weight
wjandrea
  • 28,235
  • 9
  • 60
  • 81
Leini
  • 15
  • 6

1 Answers1

2

You need to iterate through the dict items (both keys and values). Use for k, v in BMI.items().

Milan Cermak
  • 7,476
  • 3
  • 44
  • 59