Exploring Optimal Temperature Days: Python Program for Temperature Analysis

Write a python program that is given a dictionary containing the average daily temperature for each day of the week, and prints all the days on which the average temperature was between 40 and 50 degrees.

Computer Bits Daily
3 min readJul 15, 2023

Python is a versatile programming language that allows us to perform a wide range of tasks, including data manipulation and analysis. In this blog post, we will explore how to write a Python program that can analyze a dictionary containing the average daily temperature for each day of the week. The program will identify and print all the days on which the average temperature was between 40 and 50 degrees. This can be a useful tool for weather analysis or any other application that involves temperature data.

Table of Contents

  • What is Python?
  • What is a Dictionary?
  • Understanding the Problem
  • Writing the Python Program
  • Testing the Program

| Practice Python MCQ with “Python MCQ Programs Interview “ Android App.

What is Python?

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.

It is known for its simplicity and readability, making it a popular choice among beginners and experienced programmers alike.

Python offers a wide range of built-in data structures and supports various programming paradigms, including procedural, object-oriented, and functional programming.

Its versatility and ease of use have made it one of the most widely used programming languages in the world.

What is a Dictionary?

A dictionary in Python is a collection that allows us to store data in key-value pairs.

It is similar to a real-world dictionary, where words (keys) are associated with their meanings (values).

The key-value pairs are enclosed in curly brackets {} and separated by commas. Dictionaries are unordered, meaning that the items are not stored in a specific order.

Understanding the Problem

Before we start writing the Python program, let’s understand the problem statement.

We are given a dictionary that contains the average daily temperature for each day of the week.

Our task is to identify and print all the days on which the average temperature was between 40 and 50 degrees.

| Practical List — Python [ 4330701 ] [ PRACTICAL EXERCISES ]

Writing the Python Program

To solve this problem, we can iterate through the dictionary and check the average temperature for each day.

If the average temperature falls within the range of 40 to 50 degrees, we will print the corresponding day. Here’s the Python program:

# Given dictionary containing average daily temperature

temperature_dict = {

“Monday”: 45,

“Tuesday”: 50,

“Wednesday”: 38,

“Thursday”: 42,

“Friday”: 48,

“Saturday”: 55,

“Sunday”: 39

}

# Iterate through the dictionary

for day, temperature in temperature_dict.items():

if 40 <= temperature <= 50:

print(f”The average temperature on {day} was between 40 and 50 degrees.”)

| Learn Python with “ Computer Courses — All in One “

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Computer Bits Daily
Computer Bits Daily

Written by Computer Bits Daily

Learning Computer skills and Computer technology by learning and sharing

No responses yet

Write a response