Skip to content
Snippets Groups Projects
Commit c74263d8 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
.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()
def update(self):
ids = self.root.ids
try:
a = int(ids.a.text)
b = int(ids.b.text)
c = int(ids.c.text)
if a + b + c != 180:
self.classification = Classification.INVALID.value
else:
angles = frozenset((a, b, c))
if any(not 0 < angle < 180 for angle in angles):
self.classification = Classification.INVALID.value
elif 90 in angles:
self.classification = Classification.RIGHT.value
else:
self.classification = {
1: Classification.EQUILATERAL.value,
2: Classification.ISOSCELES.value,
3: Classification.SCALENE.value,
}[len(angles)]
except ValueError:
self.classification = f'{Classification.INVALID.value} (non-integer angles)'
def on_start(self):
self.update()
if __name__ == '__main__':
app = TriangleApp()
app.run()
BoxLayout:
orientation: 'vertical'
Widget:
BoxLayout:
orientation: 'horizontal'
size_hint: (1, 0)
height: 40
Widget:
size_hint: (0.25, 0)
Label:
text: 'Angle A (degrees):'
font_size: 36
TextInput:
id: a
multiline: False
write_tab: False
text: ''
font_size: 24
on_text: app.update()
Widget:
size_hint: (0.25, 0)
BoxLayout:
orientation: 'horizontal'
size_hint: (1, 0)
height: 40
Widget:
size_hint: (0.25, 0)
Label:
text: 'Angle B (degrees):'
font_size: 36
TextInput:
id: b
multiline: False
write_tab: False
text: ''
font_size: 24
on_text: app.update()
Widget:
size_hint: (0.25, 0)
BoxLayout:
orientation: 'horizontal'
size_hint: (1, 0)
height: 40
Widget:
size_hint: (0.25, 0)
Label:
text: 'Angle C (degrees):'
font_size: 36
TextInput:
id: c
multiline: False
write_tab: False
text: ''
font_size: 24
on_text: app.update()
Widget:
size_hint: (0.25, 0)
Widget:
size_hint: (1, 0)
height: 40
BoxLayout:
orientation: 'horizontal'
size_hint: (1, 0)
height: 40
Widget:
Label:
text: app.classification
font_size: 36
Widget:
Widget:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment