Ask Question
17 May, 17:14

Delete Prussia from country_capital. Sample output with input: 'Spain:Madrid, Togo:Lome, Prussia: Konigsberg' Prussia deleted? Yes. Spain deleted? No. Togo deleted? No.

+4
Answers (1)
  1. 17 May, 20:44
    0
    When deleting anything from dictionary always mention the key value in quotes.

    Ex: del country_capital['Prussia']

    if we don't mention it in quotes it will consider that Prussia as variable and gives the error Prussia is not defined.

    Code:

    user_input=input ("") #taking input from user

    entries=user_input. split (',')

    country_capital=dict (pair. split (':') for pair in entries) #making the input as dictionary

    del country_capital['Prussia'] #deleting Prussia here if we don't mention the value in quotes it will give error

    print ('Prussia deleted?', end=' ')

    if 'Prussia' in country_capital: #checking Prussia is in country_capital or not

    print ('No.')

    else:

    print ('Yes.')

    print ('Spain deleted?', end=' ')

    if 'Spain' in country_capital: #check Spain is in Country_capital or not

    print ('No.')

    else:

    print ('Yes.')

    print ('Togo deleted?', end=' ') #checking Togo is in country_capital or not

    if 'Togo' in country_capital:

    print ('No.')

    else:

    print ('Yes.')
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Delete Prussia from country_capital. Sample output with input: 'Spain:Madrid, Togo:Lome, Prussia: Konigsberg' Prussia deleted? Yes. Spain ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers