Question
Python:, This task involves simulating the setting of the temperature in a sauna. The premise is that the user comes from America and only knows
Python:,
This task involves simulating the setting of the temperature in a sauna. The premise is that the user comes from America and only knows fahrenheit, while the unit only understands celsius. So you get to create code that receives the value in fahrenheit and converts this.
You determine an appropriate temperature in a range of numbers - for example 82 to 87 degrees.
In this task, you must work with exception handling according to the study material. This means that if you enter an incorrect letter or number, the program will not crash. Then you have to solve it with a loop that iterates as long as you haven't entered a correct value.
In the task, you must create a method that is outside the main method. The new method should be used to convert Fahrenheit to Celsius. The method accepts an integer as an argument. Then the method should return an integer corresponding to Celsius.
The Celsius value should be tested if it is too low or too high. Then you write a suitable text about this. And the code for input is repeated.
Should the temperature in Celsius match a suitable temperature (between 82 and 87), the program will end with a nice message that the sauna is ready to bathe in.
Pseudocode: Initialize celsius=0 Initiate speech Do while Celsius is lower than 82 or higher than 87 Enter value for Fahrenheit Call fahr_to_cels(fahrenheit) to Celcius If Celsius is lower than 82 Print "It's too cold" Else if Celsius is higher than 87 Print "It's too hot" The temperature is now just right
The challenge: This task is very much about practicing methods and how they can be used. It is important that you practice both this with arguments (a value that is sent to the method and that is required for the method to do its job). Likewise, the method must be able to return a value (the calculated value in Celsius). A parenthesis is that it does not have to be the case at all that a method has arguments and/or return value. But in this task, that is the case. Furthermore, the challenge is that you can work with conditions and a loop for the program to function as intended. The task is quite similar to the "guess the number" task from a previous task, but that several values are correct. This can be solved with a bool variable, but it will be even better if we instead directly compare values for the right temperature with the Celsius value. You must have solved the exception handling in an acceptable way. The challenge (for grade criteria corresponding to C) means that you do not use a bool variable for the loop. Furthermore, the method that converts Fahrenheit to Celsius should accept an integer, but return a decimal number (Celsius). This is called type conversion. Exception handling should feel logical and well balanced. So that it doesn't become too cumbersome code. The most difficult challenge (for grade criteria corresponding to A) means that you must work with one more method and which must function as an overlaid method (eng: "overloaded methods"). If the user enters 0 (zero) instead of a value, the new method must be used instead and in an appropriate way. The new method (which has no arguments) should randomly generate a number and then in turn return the value to the original method (with arguments) for converting between Fahrenheit and Celsius.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started