Answer: Below is the correctly formatted code:
if 'New York' in temperatures:
if temperatures['New York'] > 90:
print('The city is melting!')
else:
print('The temperature in New York is', temperatures['New York'])
else:
print('The temperature in New York is unknown.')
Explanation:
This is the entire program:
temperatures = {
'Seattle': 56.5,
'New York': 105,
'Kansas City': 81.9,
'Los Angeles': 76.5
}
if 'New York' in temperatures:
if temperatures['New York'] > 90:
print('The city is melting!')
else:
print('The temperature in New York is', temperatures['New York'])
else:
print('The temperature in New York is unknown.')
The output will be:
The city is melting!
This program mainly comprises nested if statements. The first check determines if 'New York' exists within the temperature data. When confirmed, it moves to another if statement to see if New York's temperature exceeds 90. If true, it outputs the message, "The city is melting!". If false, it presents the actual temperature of New York. If neither condition is satisfied, it defaults to showing that the temperature is unknown. Given that New York's temperature is 105, the output reflects that the city is melting!
Proper indentation is crucial in Python, as it distinguishes code blocks without needing brackets, enhancing readability. Observe how the nested if statements are structured within the outer if statement. The else statements align appropriately beneath their respective if declarations, and print statements follow the necessary indentation.