Write a Python program to convert temperatures to and from celsius,
def C2F(c):
"""
Convert Celsius to Fahrenheit
"""
return c * 9/5 + 32
def F2C(f):
"""
Convert Fahrenheit to Celsius
"""
return (f - 32) * 5/9
def main():
line = input("Enter a temperature: ")
d = line[-1]
if d == 'C' or d == 'c':
c = float(line[:-1])
f = C2F(c)
print(f'{c}C = {f}F')
else:
if d == 'F' or d == 'f':
f = float(line[:-1])
else:
f = float(line)
c = F2C(f)
print(f'{f}F = {c:.1f}C')
if __name__ == '__main__':
main()
Comments
Leave a comment