Answer to Question #329536 in Python for Shubham Tiwari

Question #329536

Write a Python program to convert temperatures to and from celsius, 


1
Expert's answer
2022-04-17T13:54:04-0400
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS