0% found this document useful (0 votes)
12 views19 pages

Program

The document contains three Python programs that handle student scholarship eligibility based on marks, provide discounts on children's day items, and manage environmental data for cities including pollution and temperature. Each program includes variable descriptions detailing their data types and purposes. The third program features functions for calculating average temperatures, creating reports, and categorizing cities based on temperature and pollution levels.

Uploaded by

v.mahato2411
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views19 pages

Program

The document contains three Python programs that handle student scholarship eligibility based on marks, provide discounts on children's day items, and manage environmental data for cities including pollution and temperature. Each program includes variable descriptions detailing their data types and purposes. The third program features functions for calculating average temperatures, creating reports, and categorizing cities based on temperature and pollution levels.

Uploaded by

v.mahato2411
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program: (1)

a=int(input("Enter number of students:"))

for i in range(1,a+1):

print("Enter marks of student with roll number”, i)

m=int(input("Enter the total marks out of 3000:"))

p=(m/3000)*100

if(p>=85):

print("Eligible for scholarship")

else:

print("Not eligible for scholarship")

variable description
Variable Data type Description
a integer To take input the of the
number of students in a
class
i integer To run a loop for each
student in a class
m integer To input total marks
p float To store the value for

Output:
Enter number of students:34
Enter marks of student with roll number 1
Enter the total marks out of 3000:2654
Eligible for scholarship
Enter marks of student with roll number 2
Enter the total marks out of 3000:567
Not eligible for scholarship
Program: (2)

print('''Happy Children's day to every children we have a special


discount for you on each object
10% discount is being provided on stationery items
12% discount is on bags and 15% on laptops''')
print("1","To order stationery objects","2","To order bags","3","To order
laptops")
print("x is price of stationery object",",","y is price of bags",",","z is the price of
laptops")
x=12
y=250
z=32000
print(“x”,x)
print(“y”,y)
print(“z”,z)
a=int(input("Enter the variable price for the object you want to purchase:"))
if a==1:
d=10
s=((100-d)/100)*x
print("Stationery item/items bought for",",",s)
elif a==2:
d=12
s=((100-d)/100)*y
print("Bag/Bags bought for ",",",s)
elif a==3:
d=15
s=((100-d)/100)*z
print("Laptop bought for",",",s)

Variable Description:
Variable Data type Description
a integer To input the choice
number
s float To store the final price
after calculating the
discount

Output:
=RESTART:C:/Users/Dell/AppData/Local/Programs/Python/Python39/fvbvfahvjs
[Link]
Happy Children's day to every children we have a special
discount for you on each object
10% discount is being provided on stationery items
12% discount is on bags and 15% on laptops
1 To order stationery objects 2 To order bags 3 To order laptops
x is price of stationery object , y is price of bags , z is the price of laptops
x 12
y 250
z 32000
Enter the choice price for the object you want to purchase:3
Laptop bought for , 27200.0

Program : (3)
Def store_environment_data(city_data):
“””
Stores pollution levels and temperature details of various cities.

Args:
City_data (dict): A dictionary where keys are city names and
Values are dictionaries containing ‘pollution’ and
‘temperature’ data (e.g., monthly averages).
“””
# In a real application, you might store this in a file or database.
# For this example, we’ll just return the data.
Return city_data

Def calculate_average_temperature(city_data, month):


“””
Calculates the average temperature across different cities for a given month.

Args:
City_data (dict): The dictionary of city data.
Month (str): The month for which to calculate the average temperature.

Returns:
Float: The average temperature for the given month across all cities.
Returns None if no data is available for the month.
“””
Total_temp = 0
Count = 0
For city, data in city_data.items():
If month in data[‘temperature’]:
Total_temp += data[‘temperature’][month]
Count += 1
If count > 0:
Return total_temp / count
Else:
Return None

Def create_summer_temperature_report(city_data, summer_months):


“””
Creates a report of temperatures in summer for different cities.

Args:
City_data (dict): The dictionary of city data.
Summer_months (list): A list of month names considered as summer.

Returns:
Dict: A dictionary where keys are city names and values are
Dictionaries of summer month temperatures.
“””
Report = {}
For city, data in city_data.items():
Report[city] = {}
For month in summer_months:
If month in data[‘temperature’]:
Report[city][month] = data[‘temperature’][month]
Return report

Def fetch_temperature_details(city_data, city):


“””
Fetches temperature details for a specific city.

Args:
City_data (dict): The dictionary of city data.
City (str): The name of the city to fetch details for.

Returns:
Dict: A dictionary of temperature details for the city, or
None if the city is not found.
“””
If city in city_data:
Return city_data[city][‘temperature’]
Else:
Return None
Def display_results(results):
“””
Displays the final results (can be any format).

Args:
Results (any): The results to be displayed.
“””
Print(results)

Def find_extreme_temperatures(city_data):
“””
Finds the city with the maximum and minimum average temperature.

Args:
City_data (dict): The dictionary of city data.

Returns:
Tuple: A tuple containing the city with the maximum average temperature
And the city with the minimum average temperature.
Returns None, None if no data is available.
“””
Max_temp = float(‘-inf’)
Min_temp = float(‘inf’)
Max_city = None
Min_city = None

For city, data in city_data.items():


Avg_temp = sum(data[‘temperature’].values()) / len(data[‘temperature’])
If avg_temp > max_temp:
Max_temp = avg_temp
Max_city = city
If avg_temp < min_temp:
Min_temp = avg_temp
Min_city = city
Return max_city, min_city

Def check_pollution_level(city_data, city, threshold):


“””
Checks if the pollution level of a city is above a threshold.

Args:
City_data (dict): The dictionary of city data.
City (str): The name of the city to check.
Threshold (float): The pollution level threshold.

Returns:
Bool: True if the pollution level is above the threshold, False otherwise.
Returns None if the city is not found.
“””
If city in city_data:
Return city_data[city][‘pollution’] > threshold
Else:
Return None

Def categorize_cities_by_temperature(city_data, thresholds):


“””
Categorizes cities into slabs of high/medium/low temperatures.

Args:
City_data (dict): The dictionary of city data.
Thresholds (list): A list of temperature thresholds to define slabs.

Returns:
Dict: A dictionary where keys are temperature categories (e.g., “High”,
“Medium”, “Low”)
And values are lists of cities in that category.
“””
Categories = {
“High”: [],
“Medium”: [],
“Low”: []
}
For city, data in city_data.items():
Avg_temp = sum(data[‘temperature’].values()) / len(data[‘temperature’])
If avg_temp > thresholds[1]:
Categories[“High”].append(city)
Elif avg_temp > thresholds[0]:
Categories[“Medium”].append(city)
Else:
Categories[“Low”].append(city)
Return categories

# Example Usage:
City_data = {
“London”: {“pollution”: 50, “temperature”: {“Jan”: 5, “Feb”: 8, “Jul”: 25,
“Aug”: 22}},
“Paris”: {“pollution”: 60, “temperature”: {“Jan”: 3, “Feb”: 6, “Jul”: 28, “Aug”:
25}},
“Tokyo”: {“pollution”: 45, “temperature”: {“Jan”: 7, “Feb”: 10, “Jul”: 30,
“Aug”: 27}},
“Mumbai”: {“pollution”: 70, “temperature”: {“Jan”: 20, “Feb”: 22, “Jul”: 32,
“Aug”: 30}},
}

Summer_months = [“Jul”, “Aug”]

# Store Data (i)


Stored_data = store_environment_data(city_data)

# Calculate Average Temperature (ii)


Avg_temp_july = calculate_average_temperature(stored_data, “Jul”)
Print(“Average temperature in July:”, avg_temp_july)

# Create Summer Report (iii)


Summer_report = create_summer_temperature_report(stored_data,
summer_months)
Print(“Summer temperature report:”, summer_report)

# Fetch Temperature Details (iv)


London_temps = fetch_temperature_details(stored_data, “London”)
Print(“London temperature details:”, london_temps)

# Find Extreme Temperatures (vi)


Hottest, coolest = find_extreme_temperatures(stored_data)
Print(“Hottest city:”, hottest)
Print(“Coolest city:”, coolest)

# Check Pollution Level (vii)


Is_high_pollution = check_pollution_level(stored_data, “Mumbai”, 65)
Print(“Is Mumbai’s pollution high?”, is_high_pollution)

# Categorize Cities by Temperature (viii)


Temperature_categories = categorize_cities_by_temperature(stored_data, [15,
25])
Print(“Temperature categories:”, temperature_categories)
Def store_environment_data(city_data):
“””
Stores pollution levels and temperature details of various cities.

Args:
City_data (dict): A dictionary where keys are city names and
Values are dictionaries containing ‘pollution’ and
‘temperature’ data (e.g., monthly averages).
“””
# In a real application, you might store this in a file or database.
# For this example, we’ll just return the data.
Return city_data

Def calculate_average_temperature(city_data, month):


“””
Calculates the average temperature across different cities for a given month.

Args:
City_data (dict): The dictionary of city data.
Month (str): The month for which to calculate the average temperature.

Returns:
Float: The average temperature for the given month across all cities.
Returns None if no data is available for the month.
“””
Total_temp = 0
Count = 0
For city, data in city_data.items():
If month in data[‘temperature’]:
Total_temp += data[‘temperature’][month]
Count += 1
If count > 0:
Return total_temp / count
Else:
Return None

Def create_summer_temperature_report(city_data, summer_months):


“””
Creates a report of temperatures in summer for different cities.

Args:
City_data (dict): The dictionary of city data.
Summer_months (list): A list of month names considered as summer.

Returns:
Dict: A dictionary where keys are city names and values are
Dictionaries of summer month temperatures.
“””
Report = {}
For city, data in city_data.items():
Report[city] = {}
For month in summer_months:
If month in data[‘temperature’]:
Report[city][month] = data[‘temperature’][month]
Return report

Def fetch_temperature_details(city_data, city):


“””
Fetches temperature details for a specific city.

Args:
City_data (dict): The dictionary of city data.
City (str): The name of the city to fetch details for.

Returns:
Dict: A dictionary of temperature details for the city, or
None if the city is not found.
“””
If city in city_data:
Return city_data[city][‘temperature’]
Else:
Return None

Def display_results(results):
“””
Displays the final results (can be any format).
Args:
Results (any): The results to be displayed.
“””
Print(results)

Def find_extreme_temperatures(city_data):
“””
Finds the city with the maximum and minimum average temperature.

Args:
City_data (dict): The dictionary of city data.

Returns:
Tuple: A tuple containing the city with the maximum average temperature
And the city with the minimum average temperature.
Returns None, None if no data is available.
“””
Max_temp = float(‘-inf’)
Min_temp = float(‘inf’)
Max_city = None
Min_city = None

For city, data in city_data.items():


Avg_temp = sum(data[‘temperature’].values()) / len(data[‘temperature’])
If avg_temp > max_temp:
Max_temp = avg_temp
Max_city = city
If avg_temp < min_temp:
Min_temp = avg_temp
Min_city = city
Return max_city, min_city

Def check_pollution_level(city_data, city, threshold):


“””
Checks if the pollution level of a city is above a threshold.

Args:
City_data (dict): The dictionary of city data.
City (str): The name of the city to check.
Threshold (float): The pollution level threshold.

Returns:
Bool: True if the pollution level is above the threshold, False otherwise.
Returns None if the city is not found.
“””
If city in city_data:
Return city_data[city][‘pollution’] > threshold
Else:
Return None
Def categorize_cities_by_temperature(city_data, thresholds):
“””
Categorizes cities into slabs of high/medium/low temperatures.

Args:
City_data (dict): The dictionary of city data.
Thresholds (list): A list of temperature thresholds to define slabs.

Returns:
Dict: A dictionary where keys are temperature categories (e.g., “High”,
“Medium”, “Low”)
And values are lists of cities in that category.
“””
Categories = {
“High”: [],
“Medium”: [],
“Low”: []
}
For city, data in city_data.items():
Avg_temp = sum(data[‘temperature’].values()) / len(data[‘temperature’])
If avg_temp > thresholds[1]:
Categories[“High”].append(city)
Elif avg_temp > thresholds[0]:
Categories[“Medium”].append(city)
Else:
Categories[“Low”].append(city)
Return categories

# Example Usage:
City_data = {
“London”: {“pollution”: 50, “temperature”: {“Jan”: 5, “Feb”: 8, “Jul”: 25,
“Aug”: 22}},
“Paris”: {“pollution”: 60, “temperature”: {“Jan”: 3, “Feb”: 6, “Jul”: 28, “Aug”:
25}},
“Tokyo”: {“pollution”: 45, “temperature”: {“Jan”: 7, “Feb”: 10, “Jul”: 30,
“Aug”: 27}},
“Mumbai”: {“pollution”: 70, “temperature”: {“Jan”: 20, “Feb”: 22, “Jul”: 32,
“Aug”: 30}},
}

Summer_months = [“Jul”, “Aug”]

# Store Data (i)


Stored_data = store_environment_data(city_data)

# Calculate Average Temperature (ii)


Avg_temp_july = calculate_average_temperature(stored_data, “Jul”)
Print(“Average temperature in July:”, avg_temp_july)

# Create Summer Report (iii)


Summer_report = create_summer_temperature_report(stored_data,
summer_months)
Print(“Summer temperature report:”, summer_report)

# Fetch Temperature Details (iv)


London_temps = fetch_temperature_details(stored_data, “London”)
Print(“London temperature details:”, london_temps)

# Find Extreme Temperatures (vi)


Hottest, coolest = find_extreme_temperatures(stored_data)
Print(“Hottest city:”, hottest)
Print(“Coolest city:”, coolest)

# Check Pollution Level (vii)


Is_high_pollution = check_pollution_level(stored_data, “Mumbai”, 65)
Print(“Is Mumbai’s pollution high?”, is_high_pollution)

# Categorize Cities by Temperature (viii)


Temperature_categories = categorize_cities_by_temperature(stored_data, [15,
25])
Print(“Temperature categories:”, temperature_categories)
Variable – description :

You might also like