Ad
Fundamentals
Numbers
Data Types
Mathematics
Algorithms
Logic

Quick Science Lesson:
There are four major types of temparature scales (Celsius, Kelvin, Fahrenheit, and Rankine).

To convert Celsius to Kelvin simply add 273.15
EX:
3°C = 276.15K
To convert Celsius to Fahrenheit simply multiply by 9/5 and add 32
EX:
3°C = 37.4°F
To convert Celsius to Rankine simply multiply by 9/5 and add 491.67
EX:
3°C = 497.07°R

NOTE: Remember you can convert from different if you wanted

Actual Program:
Basically you will be given a list in the format [21, 'r', 'c'], which means you will have to convert 21°R to °C and return the float temperature back.

Ex #1:
Input:
[21, 'r', 'c']
Output:
-261
Ex #2:
Input:
[234.21, 'f', 'r']
Output:
693
Ex #3:
Input:
[-122, 'k', 'c']
Output:
-395

NOTE: Make sure you return only ints

# Fastest way is to convert everything to celsius and then convert to final temperature
import math
def temperature_convert(temperature):
    z = 0
    # list of if clauses to figure out steps based on 2nd value of list
    if temperature[1] == 'r':
        z = (temperature[0] - 491.67) * 5 / 9
    elif temperature[1] == 'f':
        z = (temperature[0] - 32) * 5 / 9
    elif temperature[1] == 'k':
        z = temperature[0] - 273.15
    else:
        z = temperature[0]
    # list of if clauses to figure out steps based on 3rd value of list
    if temperature[2] == 'r':
        return math.trunc((z * 9 / 5) + 491.67)
    elif temperature[2] == 'f':
        return math.trunc((z * 9 / 5) + 32)
    elif temperature[2] == 'k':
        return math.trunc(z + 273.15)
    else:
        return math.trunc(z)