Skip to content
Snippets Groups Projects
Commit 34339231 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Initial commit.

parents
No related branches found
No related tags found
No related merge requests found
*~
*.pyc
*.pyo
.idea
main.py 0 → 100644
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):
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):
ids = self.root.ids
try:
self.classification = TriangleApp.classify(int(ids.a.text), int(ids.b.text), int(ids.c.text)).value
except ValueError:
self.classification = f'{Classification.INVALID.value} (non-integer sides)'
def on_start(self):
self.update()
if __name__ == '__main__':
app = TriangleApp()
app.run()
BoxLayout:
orientation: 'vertical'
Widget:
size_hint: (1.0, 2.0)
BoxLayout:
orientation: 'horizontal'
size_hint: (1.0, 0.0)
height: sp(40)
Widget:
Label:
text: 'Side A:'
font_size: sp(36)
Widget:
size_hint: (0.25, 1.0)
TextInput:
id: a
multiline: False
write_tab: False
text: ''
font_size: sp(24)
on_text: app.update()
Widget:
BoxLayout:
orientation: 'horizontal'
size_hint: (1.0, 0.0)
height: sp(40)
Widget:
Label:
text: 'Side B:'
font_size: sp(36)
Widget:
size_hint: (0.25, 1.0)
TextInput:
id: b
multiline: False
write_tab: False
text: ''
font_size: sp(24)
on_text: app.update()
Widget:
BoxLayout:
orientation: 'horizontal'
size_hint: (1.0, 0.0)
height: sp(40)
Widget:
Label:
text: 'Side C:'
font_size: sp(36)
Widget:
size_hint: (0.25, 1.0)
TextInput:
id: c
multiline: False
write_tab: False
text: ''
font_size: sp(24)
on_text: app.update()
Widget:
Widget:
BoxLayout:
orientation: 'horizontal'
Label:
text: app.classification
font_size: sp(36)
text_size: self.size
halign: 'center'
Widget:
size_hint: (0.0, 1.5)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment