![]() ![]() Use the algorithm mentioned above to help. Use the variable fahrenheitalready defined and assign it the Fahrenheit temperature equivalent to the given Celsius temperature. You are given a variable celsiusrepresenting a temperature in Celsius. Note: the function prints out an error message if the scale given is not supported. The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32. Use the variable fahrenheit already defined and assign it the Fahrenheit temperature equivalent to the given Celsius temperature. You are given a variable celsius representing a temperature in Celsius. So now the output shows both the original scale and the converted one: Select (F) or (C): Fĩ2 degrees F is 33.333333333333336 degrees C The formula to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32. Print(source_temp, "degrees", scale, "is", m, "degrees", s) Return 'F', (source_temp * (9.0/5.0)) + 32.0 The formula to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32. It can simply return a tuple, with the destination scale as its first element #!/usr/bin/env python3 The easiest thing you can do is to have the function return the scale of the converted temperature, since it already bases its behavior on the given scale. What need help with, is to add the converted scale (F or C) to my print output. Print(source_temp, "degrees", scale, "is", m, "degrees", scale) This value is stored in a variable, say ‘cel’. In this algorithm, we will start off by taking the temperature to be convert into Fahrenheit as user input. Using the values supplied by the user, the program should then call the ‘converttemp’ function and pass in the two arguments, along these lines: converttemp (scaleF, sourcetemp98.6) and the subroutine should produce a line of output that looks like this (for Fahrenheit to Celsius): 98.6 degrees F is 37. Source_temp = int(input("What is the temperature: " )) Explanation: We can covert a given temperature form Celsius to Fahrenheit using the formula: f ( (5/9) cel ) + 32. I have the following code so far: #!/usr/bin/env python3ĭef convert_temp(scale=None, source_temp=None): The first temperature and scale that you should report are those that the user entered, followed by the converted temperature and other scale. Or, for a Celsius to Fahrenheit conversion: 100.0 degrees C is 212.0 degrees F Using the values supplied by the user, the program should then call the ‘convert_temp’įunction and pass in the two arguments, along these lines: convert_temp(scale=F, source_temp=98.6)Īnd the subroutine should produce a line of output that looks like this (for Fahrenheit to Celsius): 98.6 degrees F is 37.0 degrees C ![]() Your program should prompt the user to enter a temperature scale (assume the user will choose to type ‘F’ or ‘C’) and then prompt the user to enter a number of degrees. Then write a short program to use the function you wrote (both the function and program should be part of the same file). The function signature should be: def convert_temp( scale=None, source_temp=None ): Finally, this function should print out the original temperature and scale as well as the converted temperature and scale.It should then convert the original temperature from Fahrenheit to Celsius or from Celsius to Fahrenheit, as appropriate.It must accept and read two arguments that are passed to it: first, the temperature scale of the original temperature (only ‘F’ or ‘C’ should be used) and second, the number of degrees of the original.It should be able to handle both Fahrenheit to Celsius conversions as well as Celsius to Fahrenheit conversions.If the input is not valid, or if it is not either 1 or 2, print a message to the user.Write a function for temperature conversion named ‘convert_temp’. Similar to the above step, do the conversion from Celsius to Fahrenheit. Finally, print out the result to the user. Ask the user to enter the Fahrenheit value, store it in Fahrenheit variable and calculate the Celsius using the same formula we have seen above. If the value of choice is 1, the conversion is for Fahrenheit to Celsius. Ĭheck the value of choice using an if-else if-else condition.Read the user input value and store it in the choice variable. Īsk the user to enter 1 for Fahrenheit to Celsius and 2 for Celsius to Fahrenheit conversion.choice is an integer variable to store the option selected by the user. We are creating two floating-point values to store the Fahrenheit and Celsius values. Main() is the starting method of a C++ program. ![]() The commented numbers in the above program denote the step numbers below: Program to convert Celsius into Fahrenheit on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree. # include using namespace std //1 int main ( ) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |