DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Worksheet 1
Student Name: Amarjeet Raj UID: 23BCS13589
Branch: BE - CSE Section/Group: 809 - B
Semester: 3 Date of Performance: 06/08/2024
Subject Name: Python Subject Code: 23CSP-201
1. Aim:
To create a a temperature conversion tool to help users convert between
Celsius and Fahrenheit scales.
2. Requirements (Hardware/Software):
Programmiz, GBD online compiler
3. Procedure:
def celsius_to_far(celsius): return
(celsius * 9/5) + 32
def fahrenheit_to_cel(fahrenheit):
return (fahrenheit - 32) * 5/9
def get_temperature_input(check):
while True:
try:
temp = float(input(check))
return temp
except ValueWrong:
print("Invalid input. Please enter a numeric value.")
def main():
while True:
print("\nTemperature Converter")
print("1. Convert Celsius to Fahrenheit")
print("2. Convert Fahrenheit to Celsius")
print("3. Exit")
choice = input("Choose the conversion direction (1/2/3): ").strip()
if choice == '1':
celsius = get_temperature_input("Enter temperature in Celsius: ")
fahrenheit = celsius_to_far(celsius)
print(f"{celsius}°C is {round(fahrenheit, 1)}°F")
elif choice == '2':
fahrenheit = get_temperature_input("Enter temperature in Fahrenheit: ")
celsius = fahrenheit_to_cel(fahrenheit)
print(f"{fahrenheit}°F is {round(celsius, 1)}°C")
elif choice == '3':
print("Exiting the temperature converter.")
break
else:
print("Invalid choice. Please select 1, 2, or 3.")
if name == " main ":
main()
4. Output:
5. Learning Outcome:
Learnt basic python coding.
Learnt using operators