Ask Question
1 February, 01:25

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

+3
Answers (1)
  1. 1 February, 03:41
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers