my function is for editing the “patient” dictionary. It runs smoothly on the first run but i get a “too many values to unpack (expected 2)” on “for k, v in patient.items():” once the program reruns itself (the else part).
def approval():
print('do you approve the information below?')
print(' ')
number = 0
change = []
for k, v in patient.items():
number += 1
print('%s. %s: %s' % (number, k, v))
change.append(k)
print(' ')
a = int(input('In case of approval send 100, else send the number that must be edited '))
if a == 100:
print('!Your information has been approved!')
else:
c = str(input('Please enter the correct %s : ' % (change[a-1])))
patient[change[a-1]] = c
approval()
Can you paste in the whole error message and the traceback? Normally it
will show the exact line involved and important other information.
On the face of it, this line:
for k, v in patient.items():
should work just fine, because dict.items yields 2-tuples.
One possibility is that the error is for another line or that patient
isn’t what you thought (not a dict). Try printing out the value of patient just before the for-loop to ensure it is what you expect.
weirdly, the whole problem has just disappeared
I haven’t changed the code, but, poof, there is no problem now. I can edit it as much as I want
Just another question, how can I break strings so that my code can fit pep8?
This is why it’s important to make sure you can produce a proper minimal reproducible example of issues. The gold standard is to make sure, before posting:
Does this code look right in the preview?
Can I copy this code out of the preview into a new file and run it without adding or changing anything?
When I do that, can I directly see the exact problem I want to ask about, without interacting with the program?