Advertisement
Sax

Fan Blows Hard

Sax
Feb 6th, 2012
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from math import *
  3.  
  4. class mf(object):
  5.  
  6.     def __init__(self, p):
  7.         self._p = p[:]
  8.  
  9.  
  10. class finaltrapecio(mf):
  11.  
  12.     def evaluate(self,x):
  13.         if x <= self._p[0]:
  14.             return 1
  15.         elif self._p[0] < x <= self._p[1]:
  16.             return (self._p[1] - x)/(self._p[1] - self._p[0])
  17.         else:
  18.             return 0
  19.            
  20.  
  21. class trapecio(mf):
  22.  
  23.     def evaluate(self,x):
  24.         if x<=self._p[0]:
  25.             return 0
  26.         elif self._p[0] < x <= self._p[1]:
  27.             return (x - self._p[0])/(self._p[1] - self._p[0])
  28.         elif self._p[1] < x <= self._p[2]:
  29.             return 1
  30.         elif self._p[2] < x <= self._p[3]:
  31.             return 1 - (x - self._p[2])/(self._p[3] - self._p[2])
  32.         else:
  33.             return 0
  34.  
  35. class principiotrapecio(mf):
  36.  
  37.     def evaluate(self,x):
  38.         if x <= self._p[0]:
  39.             return 0
  40.         elif self._p[0] < x < self._p[1]:
  41.             return (x - self._p[0])/(self._p[1] - self._p[0])
  42.         else:
  43.             return 1
  44.  
  45. class temp(object):
  46.     def __init__(self, t):
  47.         self.t = t
  48.         self.eval_ratio = None
  49.  
  50. #Creacion de las figuras
  51. cold = finaltrapecio([15,20])
  52. warm = trapecio([17, 20, 24, 28])
  53. hot = principiotrapecio([24, 28])
  54.  
  55. #Pide la temperatura
  56. given = temp(raw_input("Dame la temperatura: "))
  57.  
  58. #Evalúa la temperatura en las figuras
  59. cold_ratio = cold.evaluate(float(given.t))
  60. warm_ratio = warm.evaluate(float(given.t))
  61. hot_ratio = hot.evaluate(float(given.t))
  62.  
  63. if cold_ratio > warm_ratio:
  64.     print "Hay frio"
  65.     eval_ratio = cold_ratio
  66.     fan = False
  67. elif warm_ratio > hot_ratio:
  68.     print "Esta cálido"
  69.     fan = True
  70.     eval_ratio = warm_ratio
  71. else:
  72.     print "Hace calor"
  73.     eval_ratio = hot_ratio
  74.     fan = True
  75.  
  76. if eval_ratio == 0.5:
  77.     print "dos dos"
  78. elif eval_ratio < 0.5:
  79.     print "un poco"
  80. else:
  81.     print "bastante"
  82.  
  83. if fan == False:
  84.     print "Abanico apagado"
  85. else:
  86.     print "Abanico prendido"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement