Lecture

Coding Quiz - Python Temperature Converter

This coding quiz involves writing a function to convert temperatures between Celsius(C) and Fahrenheit(F).

The solution function should take a temperature in Celsius and convert it to Fahrenheit, or take a temperature in Fahrenheit and convert it to Celsius.

Function Signature
def solution(temperature, scale): # Write your code here return # Write your return value here
  • temperature is the parameter representing the temperature you want to convert.

  • scale takes one of two values: C (Celsius) or F (Fahrenheit).

  • Use conditional statements to write code that converts Celsius to Fahrenheit when scale is C, and Fahrenheit to Celsius when scale is F.


Constraints

  • The input temperature should be either an integer or a float.

  • Use the following formulas for conversion between Celsius and Fahrenheit:

    • From Celsius to Fahrenheit: (Celsius temperature × 9/5) + 32
    • From Fahrenheit to Celsius: (Fahrenheit temperature - 32) × 5/9

Example Input and Output

  • Input: Celsius 25, Output: Fahrenheit 77

  • Input: Fahrenheit 77, Output: Celsius 25

Mission
0 / 1

When writing a function in Python to convert Celsius (C) to Fahrenheit (F), what is the formula for converting Celsius to Fahrenheit?

(Celsius temperature × 5/9) + 32

(Celsius temperature × 9/5) - 32

(Celsius temperature × 9/5) + 32

(Celsius temperature - 32) × 5/9

Lecture

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help