Python Worksheet12
Python Worksheet12
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")
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")
else:
print("Invalid choice. Please select 1, 2, or 3.")
5. Learning Outcome:
Learnt basic python coding.
Learnt using operators