Skip to content
Snippets Groups Projects
Select Git revision
  • d0356d6bd035c629a9e2fcfa2b88b6ec60b31184
  • 3.9 default
  • develop
  • 6.0
  • 5.0
  • 4.0
  • scrutinizer-patch-4
  • scrutinizer-patch-3
  • scrutinizer-patch-2
  • scrutinizer-patch-1
  • 3.7
  • 3.8
  • 3.6
  • 3.9_backported
  • 3.8_backported
  • 3.7_backported
  • 3.5
  • 3.6_backported
  • 3.5_backported
  • 3.4
  • 3.3_backported
  • 6.0.4
  • 6.0.3
  • 5.0.7
  • 6.0.2
  • 6.0.1
  • 5.0.6
  • 6.0.0
  • 5.0.5
  • 6.0.0-rc
  • 5.0.4
  • 6.0.0-beta
  • 5.0.3
  • 4.0.6
  • 5.0.2
  • 5.0.1
  • 4.0.5
  • 5.0.0
  • 4.0.4
  • 5.0.0-rc2
  • 5.0.0-rc1
41 results

api_commande.class.php

Blame
  • main.py 1.56 KiB
    from enum import Enum
    
    from kivy.app import App
    from kivy.properties import StringProperty
    
    
    class Classification(Enum):
        INVALID = 'Invalid'
        EQUILATERAL = 'Equilateral'
        ISOSCELES = 'Isosceles'
        RIGHT = 'Right'
        SCALENE = 'Scalene'
    
    
    class TriangleApp(App):
        a = StringProperty('')
        b = StringProperty('')
        c = StringProperty('')
        classification = StringProperty()
    
        @staticmethod
        def classify(a, b, c):  # buggy
            if a * b * c < 0:
                return Classification.INVALID
            if a == b and b == c:
                return Classification.EQUILATERAL
            if a == b or b == c:
                return Classification.ISOSCELES
            maximum = a
            if b > maximum:
                maximum = b
                if c > maximum:
                    maximum = c
            semiperimeter = a + b + c / 2
            if maximum > semiperimeter:
                return Classification.INVALID
            if a ** 2 + b ** 2 == c ** 2 or b ** 2 + a ** 2 == c ** 2 or c ** 2 + b ** 2 == a ** 2:
                return Classification.RIGHT
            return Classification.SCALENE
    
        def update(self):
            try:
                self.classification = TriangleApp.classify(int(self.a), int(self.b), int(self.c)).value
            except ValueError:
                self.classification = f'{Classification.INVALID.value} (non-integer sides)'
    
        def on_start(self):
            self.update()
    
        def on_a(self, _, __):
            self.update()
    
        def on_b(self, _, __):
            self.update()
    
        def on_c(self, _, __):
            self.update()
    
    
    if __name__ == '__main__':
        app = TriangleApp()
        app.run()