Ask Question

Write a program that repeatedly asks the user for a scale f or a c (for "fahrenheit" or "celsius") on one line followed by an integer temperature on the next line. it then converts the given temperature to the other scale. use the formulas: mips

+1
Answers (1)
  1. 23 March, 15:53
    0
    You should really specify what language you're using when you're asking a programming related question. I did modify the input slightly, to use xc or xf, where x is the given temperature.

    Here it is in Python:

    import re

    def to_celsius (fahrenheit):

    return (fahrenheit - 32) / 1.8

    def to_fahrenheit (celcius):

    return celcius * 1.8 + 32

    while True:

    _in = input (). lower ()

    if re. match (r'/d + (./d+) ? c', _in):

    print (f'{_in} is {to_fahrenheit (float (_in. replace ("c", ""))) }f')

    elif re. match (r'/d + (./d+) ? f', _in):

    print (f'{_in} is {to_celsius (float (_in. replace ("f", ""))) }c')

    else:

    print ('Invalid input.')
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that repeatedly asks the user for a scale f or a c (for "fahrenheit" or "celsius") on one line followed by an integer ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers