Ask Question

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. 3 April, 18:12
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers