Python Programming - Objects - Discussion
Discussion Forum : Objects - General Questions (Q.No. 15)
15.
Consider the following Python code:
class Temperature:
def __init__(self, celsius):
self.celsius = celsius
def to_fahrenheit(self):
return (self.celsius * 9/5) + 32
If you create an instance of the `Temperature` class called my_temp
with a Celsius value of 25 and then call my_temp.to_fahrenheit()
, what will be the result?
Answer: Option
Explanation:
The
to_fahrenheit
method converts Celsius to Fahrenheit using the formula (Celsius * 9/5) + 32. For the given instance, it would be (25 * 9/5) + 32 = 77.
Discussion:
Be the first person to comment on this question !
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers