def main():
    myTimer = timer.begin_timer()
    stringer.show_welcome(NAME)
    converted_temp = 0.0
    while True:
        converter = Temp()  # create instance of Temp class obj
        print()
        # get input from the user
        scale = input("Enter current scale \'F\' or \'C\':\t")
        if scale.lower() != 'c' and scale.lower() != 'f':
            print("ERROR, invalid scale. Please try again.")
            continue
        try:
            temperature = float(input("Enter current temperature:\t"))
        except ValueError:
            print("ERROR, temperature should be a number. Please try again.")
            continue

        if scale.lower() == 'f':
            converted_temp = converter.getCelsius(temperature)
            print("Degrees Celsisus = ", end=" ")
        else:
            converted_temp = converter.getFahrenheit(temperature)
            print("Degrees Fahrenheit = ", end=" ")

        print(str(converted_temp))

        choice = input("Go again? (y/n): ")
        if choice.lower() != "y":
            break
    # end while loop
    timer.stop_timer(myTimer)
    print("Bye!")
Example #2
0
 def TempIn(self, N=5):
     "average over N readings"
     temp_in = Temp()
     self.temp_in_hist = ((self.temp_in_hist if hasattr(self,'temp_in_hist') else []) + \
                          [float(temp_in)])[-N:]
     self.temp_in = round(mean(self.temp_in_hist),1)
     self.call['temp_in'] = ["",""]
def convert_temp():
    option = int(input("Enter a menu option: "))
    if option == 1:
        f = int(input("Enter degrees Fahrenheit: "))
        holder = Temp()
        holder.set_fahrenheit(f)
        c = holder.get_celsius()
        c = round(c, 2)
        print("Degrees Celsius:", c)
    elif option == 2:
        c = int(input("Enter degrees Celsius: "))
        holder = Temp()
        holder.set_celsius(c)
        f = holder.get_fahrenheit()
        f = round(f, 2)
        print("Degrees Fahrenheit:", f)
    else:
        print("You must enter a valid menu number.")
Example #4
0
def convert_temp():
    option = int(input("Enter a menu option: "))
    temp = Temp()
    if option == 1:
        f = int(input("Enter degrees Fahrenheit: "))
        temp.setFahrenheit(f)
        print("Degrees Celsius:", temp.getCelsius())    
    elif option == 2:
        c = int(input("Enter degrees Celsius: "))
        temp.setCelsius(c)
        print("Degrees Fahrenheit:", temp.getFahrenheit())
    else:
        print("You must enter a valid menu number.")
Example #5
0
    def __init__(self):
        # инициализация переменных
        self.any_button = False
        self.button_n = {}
        for k in range(1, 5):
            self.button_n.update({k: False})

        # инициализация GPIO
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)

        # инициализация устройств
        self.display = Display()
        self.buttons = Buttons(self)
        self.t = Temp()
Example #6
0
def convert_temp():
    temp = Temp()
    option = int(input("Enter a menu option: "))
    if option == 1:
        f = int(input("Enter degrees Fahrenheit: "))
        c = temp.setFahrenheit(f)
        c = temp.getCelsius(f)
        # c = temp.to_celsius(f)
        # c = round(c, 2)
        print("Degrees Celsius:", c)
    elif option == 2:
        c = int(input("Enter degrees Celsius: "))
        f = temp.setCelsius(c)
        f = temp.getFahrenheit(c)
        # f = temp.to_fahrenheit(c)
        # f = round(f, 2)
        print("Degrees Fahrenheit:", f)
    else:
        print("You must enter a valid menu number.")
Example #7
0
 def run(self):
     self.char_temp.set_value(Temp())
 def test_get_temperature(self):
     """Check if the temperature is correct from text into file"""
     obj_temperature = Temp()
     file = "71 01 55 05 7f a5 a5 66 84 : crc=84 YES \n71 01 55 05 7f a5 a5 66 84 t=23062"
     data = obj_temperature.get_temperature(file)
     assert data == 23.062
 def test_get_temp_to_send_with_none(self):
     """Check if the temperature choice is correct from list with 1 temperature between None value"""
     obj_temperature = Temp()
     list_temp = [None, 20.01, None]
     data = obj_temperature.get_temp_to_send(list_temp)
     assert data == 20.01
 def test_get_temp_to_send(self):
     """Check if the temperature choice is the last from list with 3 temperatures"""
     obj_temperature = Temp()
     list_temp = [15.52, 20.01, 25.06]
     data = obj_temperature.get_temp_to_send(list_temp)
     assert data == 25.06