Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Republic of the Philippines

BATANGAS STATE UNIVERSITY


The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: coe.alangilan@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph

College of Engineering - Department of Electrical Engineering

Bachelor of Science in Computer Engineering

CpE 401: COMPUTER PROGRAMMING 1


2nd Semester A.Y. 2023 – 2024

Activity 2
SELECTION STATEMENTS

SUBMITTED BY:
Abrigo, Renz Christian, B.

COE - 1203

SUBMITTED TO:
Sir Mark Rondol P. Abdon

Leading Innovations, Transforming Lives, Building the Nation


ACTIVITY 2: SELECTION STATEMENTS

A. Create a simple Python HVAC (Heating, Ventilation, and Air Conditioning) system's operation based on the
outdoor temperature.

1. Prompt the user to input the outdoor temperature in Fahrenheit.


2. Check Temperature Range:
● If the outdoor temperature is less than 32°F:

● Activate heating systems.

● Ensure all heating units are operational.

● Else, if the outdoor temperature is between 32°F and 50°F:

● Increase heating output to maintain indoor comfort levels.

● Else, if the outdoor temperature is between 50°F and 65°F:

● Reduce heating output.

● Consider natural ventilation to maintain comfort.

● Else, if the outdoor temperature is between 65°F and 80°F:

● Begin cooling operations.

● Ensure all cooling units are operational.

● Else, if the outdoor temperature is 80°F or higher:

● Activate cooling systems.

● Optimize airflow to maintain a comfortable indoor temperature.


3. Display the appropriate message based on the outdoor temperature range and HVAC system adjustments.

B. Create a program that calculates airspeed based on altitude and temperature


1. Take input for altitude (in feet) and temperature (in Fahrenheit) from the user.
2. Check for error conditions:
● If altitude is negative, print an error message.

● If altitude exceeds 36,000 feet, print an error message.

● If temperature is below absolute zero, print an error message.


3. If no errors are found, calculate airspeed using the provided formula:

4. Print the calculated airspeed in two decimal point format.

Paste your code here use comments to properly document your program.
print("Abrigo, Renz Christian B.\nCOE-1203\nACTIVITY 2: Selection Statements")

#Task A
#Prompt the user to input the outdoor temperature in Fahrenheit.
temperature = float(input("Enter the outdoor temperature in Fahrenheit: "))

#Creating a simple Python HVAC (Heating, Ventilation, and Air Conditioning)


system's operation based on the outdoor temperature.
#Displays the appropriate message based on the outdoor temperature range and
HVAC system adjustments.
if temperature < 32:
print("The outdoor temperature is: ", temperature, "degrees Fahrenheit",
"\nActivate heating systems.\nEnsure all heating units are operational.")
elif (temperature >= 32) and (temperature < 50):
print ("The outdoor temperature is: ", temperature, "degrees Fahrenheit",
"\nIncrease heating output to maintain indoor comfort levels.")
elif (temperature >= 50) and (temperature < 65):
print ("The outdoor temperature is: ", temperature, "degrees Fahrenheit",
"\nReduce heating output. \nConsider natural ventilation to maintain
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: coe.alangilan@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph

College of Engineering - Department of Electrical Engineering

comfort.")
elif (temperature >= 65) and (temperature < 80):
print ("The outdoor temperature is: ", temperature, "degrees Fahrenheit",
"\nBegin cooling operations. \nEnsure all cooling units are operational.")
else:
print("The outdoor temperature is: ", temperature, "degrees Fahrenheit",
"\nActivate cooling systems. \nOptimize airflow to maintain a comfortable
indoor temperature.")

# Task B
# Create a program that calculates airspeed based on altitude and temperature
# Take input for altitude (in feet) and temperature (in Fahrenheit) from the
user.
altitude = float(input("Enter altitude (in feet): "))
temperature = float(input("Enter temperature (in Fahrenheit): "))

# Code for calculating airspeed


airspeed = format((((7 * altitude * temperature) / 2) ** 0.5), ".2f")

# If altitude is negative, print an error message.


if altitude < 0:
print("Error: Altitude can't be negative")

# If altitude exceeds 36,000 feet, print an error message.


elif altitude > 36000:
print("Error: Altitude can't exceed 36000 feet")

# If temperature is below absolute zero, print an error message.


elif temperature < -459.67:
print("Error: Temperature can't be below absolute zero.")

# If no errors are found, calculate and print the airspeed, and report in 2
decimal points
else:
print("The calculated airspeed is: ", airspeed, "units")

Leading Innovations, Transforming Lives, Building the Nation


Snapshot of the python code and Snapshot of the output

Task A:

If temperature is below 32 degrees Fahrenheit:

If temperature is between 32 to 50 degrees Fahrenheit:


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: coe.alangilan@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph

College of Engineering - Department of Electrical Engineering

If temperature is between 50 to 65 degrees Fahrenheit:

If temperature is between 65 to 80 degrees Fahrenheit:

Leading Innovations, Transforming Lives, Building the Nation


If temperature is above 80 degrees Fahrenheit:
Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: coe.alangilan@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph

College of Engineering - Department of Electrical Engineering

Task B:
Calculated the airspeed:

Leading Innovations, Transforming Lives, Building the Nation


If altitude is negative:

If altitude exceeded 36,000 feet:


Republic of the Philippines
BATANGAS STATE UNIVERSITY
The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 local 2121 / 2221
E-mail Address: coe.alangilan@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph

College of Engineering - Department of Electrical Engineering

If temperature is below absolute zero:

Leading Innovations, Transforming Lives, Building the Nation

You might also like