Ask Question
19 March, 16:03

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

+4
Answers (1)
  1. 19 March, 17:22
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers