Tutorialspoint
Problem
Solution
Submissions

Convert Celsius to Fahrenheit

Certification: Basic Level Accuracy: 68.98% Submissions: 332 Points: 5

Write a Python program that converts a temperature in Celsius to Fahrenheit.

Example 1
  • Input: 0
  • Output: 32.0
  • Explanation:
    • Step 1: Apply the formula F = (C × 9/5) + 32.
    • Step 2: F = (0 × 9/5) + 32 = 0 + 32 = 32.0.
    • Step 3: Return 32.0 as the result.
Example 2
  • Input: 37
  • Output: 98.6
  • Explanation:
    • Step 1: Apply the formula F = (C × 9/5) + 32.
    • Step 2: F = (37 × 9/5) + 32 = 66.6 + 32 = 98.6.
    • Step 3: Return 98.6 as the result.
Constraints
  • -273.15 ≤ celsius ≤ 10^6 (temperature above absolute zero)
  • Time Complexity: O(1)
  • Space Complexity: O(1)
NumberBooleanCapgeminiEY
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Use the formula: fahrenheit = (celsius * 9/5) + 32
  • Use lambda function: convert = lambda c: (c * 9/5) + 32
  • Use multiplication by 1.8 instead of 9/5: fahrenheit = (celsius * 1.8) + 32

The following are the steps to convert Celsius to Fahrenheit:

  • Define a function `celsius_to_fahrenheit(celsius)`.
  • Convert using the formula `(celsius * 9/5) + 32`.
  • Return the converted temperature.
  • Call `celsius_to_fahrenheit(0)` and store the result.
  • Print the Fahrenheit value.

Submitted Code :