+ 1

i have an error in this code can anybody modify it

Country = input("enter a country : ") capitals = { "Afghanistan": "Kabul", . . .(all a to z country with capitals are here i have not mentioned all as the desciption has a limit and the code is lenghty) . . . "Zimbabwe": "Harare", } Country, capitals = c(list(capitals.items())) print(f"the capital of {Country} is {capitals}.")

2nd Mar 2022, 1:12 PM
prajakta gurav
4 Answers
+ 5
Pg1001 As capitals is a dictionary so use get function to get value like: print (capitals.get(country))
2nd Mar 2022, 1:46 PM
A͢J
A͢J - avatar
+ 3
@AJ i have tried now its working fine thanks
2nd Mar 2022, 3:36 PM
prajakta gurav
+ 3
The second last line isn't necessary here. You can do this instead print(f"the capital of {Country} is {capitals[Country]}.")
2nd Mar 2022, 3:45 PM
Simba
Simba - avatar
+ 2
@Simba pls see the code now it was a lenghty code hence there is a limit on range of question
2nd Mar 2022, 3:37 PM
prajakta gurav