Monuments of a city
Write a Python program that accepts a city name (Pune or Mumbai) and displays its monuments.
Pune
Enter city name: Pune Shaniwar Wada Lal Mahal Sinhagad Fort
Approach
- Compare the city name and print the matching monuments.
Solution
city = input("Enter city name: ").strip().title()if city == "Pune": monuments = ["Shaniwar Wada", "Lal Mahal", "Sinhagad Fort"]elif city == "Mumbai": monuments = ["Gateway of India", "Chhatrapati Shivaji Terminus", "Elephanta Caves"]else: monuments = [] if monuments: for m in monuments: print(m)else: print("No data for", city)Enter city name: Pune Shaniwar Wada Lal Mahal Sinhagad Fort
Line by line
title() makes “pune” and “PUNE” match “Pune”.
An empty list is falsy, so the else branch handles unknown cities.
Learn the concept
New to this topic? Read the lesson, then come back.