Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from math import *
- class mf(object):
- def __init__(self, p):
- self._p = p[:]
- class finaltrapecio(mf):
- def evaluate(self,x):
- if x <= self._p[0]:
- return 1
- elif self._p[0] < x <= self._p[1]:
- return (self._p[1] - x)/(self._p[1] - self._p[0])
- else:
- return 0
- class trapecio(mf):
- def evaluate(self,x):
- if x<=self._p[0]:
- return 0
- elif self._p[0] < x <= self._p[1]:
- return (x - self._p[0])/(self._p[1] - self._p[0])
- elif self._p[1] < x <= self._p[2]:
- return 1
- elif self._p[2] < x <= self._p[3]:
- return 1 - (x - self._p[2])/(self._p[3] - self._p[2])
- else:
- return 0
- class principiotrapecio(mf):
- def evaluate(self,x):
- if x <= self._p[0]:
- return 0
- elif self._p[0] < x < self._p[1]:
- return (x - self._p[0])/(self._p[1] - self._p[0])
- else:
- return 1
- class temp(object):
- def __init__(self, t):
- self.t = t
- self.eval_ratio = None
- #Creacion de las figuras
- cold = finaltrapecio([15,20])
- warm = trapecio([17, 20, 24, 28])
- hot = principiotrapecio([24, 28])
- #Pide la temperatura
- given = temp(raw_input("Dame la temperatura: "))
- #Evalúa la temperatura en las figuras
- cold_ratio = cold.evaluate(float(given.t))
- warm_ratio = warm.evaluate(float(given.t))
- hot_ratio = hot.evaluate(float(given.t))
- if cold_ratio > warm_ratio:
- print "Hay frio"
- eval_ratio = cold_ratio
- fan = False
- elif warm_ratio > hot_ratio:
- print "Esta cálido"
- fan = True
- eval_ratio = warm_ratio
- else:
- print "Hace calor"
- eval_ratio = hot_ratio
- fan = True
- if eval_ratio == 0.5:
- print "dos dos"
- elif eval_ratio < 0.5:
- print "un poco"
- else:
- print "bastante"
- if fan == False:
- print "Abanico apagado"
- else:
- print "Abanico prendido"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement