+ 1

Guyz my code isn't running kindly check.it says str object does not support item assignment.

def phone_sum(dictionary): for i in range (12): x=input("enter name:") dictionary[x]=int(input("enter phone number:")) print("total contacts are",len(dictionary)) return dictionary print(phone_sum('personal_phonedir')) def phone_del(dictionary): dictionary.popitem() print("dictionary when member is removed:") return dictionary print(phone_del("personal_phonedir"))

20th Jan 2022, 12:49 PM
SAfiullaH KhoKhar
SAfiullaH KhoKhar - avatar
5 Answers
0
You are passing a string but working like as it is dictionary. Define empty dictionary and pass it to function... Then it works...
20th Jan 2022, 12:58 PM
Jayakrishna 🇼🇳
0
Could you write a line couldn't understand.
20th Jan 2022, 1:03 PM
SAfiullaH KhoKhar
SAfiullaH KhoKhar - avatar
0
#corrected code ph_dict={} #empty dict now, you can add values by phone_sum and delete by phone_del functions def phone_sum(dictionary): for i in range (2): x=input("enter name:\n") dictionary[x]=int(input("enter phone number:\n")) print("total contacts are",len(dictionary)) return dictionary def phone_del(dictionary): dictionary.popitem() print("dictionary when member is removed:") return dictionary print(phone_sum(ph_dict)) #passing empty dict print(phone_del(ph_dict)) #passing modified dict
20th Jan 2022, 1:08 PM
Jayakrishna 🇼🇳
0
Thanks alot really đŸ„ș
20th Jan 2022, 1:08 PM
SAfiullaH KhoKhar
SAfiullaH KhoKhar - avatar
0
You're welcome..
20th Jan 2022, 1:10 PM
Jayakrishna 🇼🇳