Python Practice › If-Else Programs › Program 59
Monuments of a city
Write a Python program that accepts a city name (Pune or Mumbai) and displays its monuments.
Input
Pune
Output
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)Outputtyped input: Pune
Enter city name: Pune Shaniwar Wada Lal Mahal Sinhagad Fort
Line by line
Line 1
title() makes “pune” and “PUNE” match “Pune”.
Line 9
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.