+ 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"))
5 Antworten
0
You are passing a string but working like as it is dictionary.
Define empty dictionary and pass it to function... Then it works...
0
Could you write a line couldn't understand.
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
0
Thanks alot really 🥺
0
You're welcome..