Skip to content

Commit 6089b11

Browse files
add: GUI and tested implemented geometry analyser.
1 parent 746f0f5 commit 6089b11

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

area_of_square_app.py

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
__author__ = "Nitkarsh Chourasia"
2+
__author_GitHub_profile__ = "https://github.com/NitkarshChourasia"
3+
__author_email_address__ = "[email protected]"
4+
__created_on__ = "10/10/2021"
5+
__last_updated__ = "10/10/2021"
6+
7+
from word2number import w2n
8+
9+
10+
def convert_words_to_number(word_str):
11+
"""
12+
Convert a string containing number words to an integer.
13+
14+
Args:
15+
- word_str (str): Input string with number words.
16+
17+
Returns:
18+
- int: Numeric equivalent of the input string.
19+
"""
20+
numeric_result = w2n.word_to_num(word_str)
21+
return numeric_result
22+
23+
24+
# Example usage:
25+
number_str = "two hundred fifteen"
26+
result = convert_words_to_number(number_str)
27+
print(result) # Output: 215
28+
29+
30+
class Square:
31+
def __init__(self, side=None):
32+
if side is None:
33+
self.ask_side()
34+
# else:
35+
# self.side = float(side)
36+
else:
37+
if not isinstance(side, (int, float)):
38+
try:
39+
side = float(side)
40+
except ValueError:
41+
# return "Invalid input for side."
42+
raise ValueError("Invalid input for side.")
43+
else:
44+
self.side = float(side)
45+
# Check if the result is a float and remove unnecessary zeros
46+
47+
self.calculate_square()
48+
self.truncate_decimals()
49+
50+
# If ask side or input directly into the square.
51+
# That can be done?
52+
def calculate_square(self):
53+
self.area = self.side * self.side
54+
return self.area
55+
56+
# Want to add a while loop asking for the input.
57+
# Also have an option to ask the user in true mode or in repeat mode.
58+
def ask_side(self):
59+
# if true bool then while if int or float then for loop.
60+
# I will have to learn inheritance and polymorphism.
61+
condition = 3
62+
# condition = True
63+
if condition == True and isinstance(condition, bool):
64+
while condition:
65+
n = input("Enter the side of the square: ")
66+
self.side = float(n)
67+
elif isinstance(condition, (int, float)):
68+
for i in range(_=condition):
69+
n = input("Enter the side of the square: ")
70+
self.side = float(n)
71+
# n = input("Enter the side of the square: ")
72+
# self.side = float(n)
73+
# return
74+
75+
def truncate_decimals(self):
76+
return (
77+
f"{self.area:.10f}".rstrip("0").rstrip(".")
78+
if "." in str(self.area)
79+
else self.area
80+
)
81+
82+
# Prettifying the output.
83+
84+
def calculate_perimeter(self):
85+
return 4 * self.side
86+
87+
def calculate_perimeter_prettify(self):
88+
return f"The perimeter of the square is {self.calculate_perimeter()}."
89+
90+
def calculate_area_prettify(self):
91+
return f"The area of the square is {self.area}."
92+
93+
def truncate_decimals_prettify(self):
94+
return f"The area of the square is {self.truncate_decimals()}."
95+
96+
97+
if __name__ == "__main__":
98+
output_one = Square()
99+
truncated_area = output_one.truncate_decimals()
100+
# print(output_one.truncate_decimals())
101+
print(truncated_area)
102+
103+
104+
# add a while loop to keep asking for the user input.
105+
# also make sure to add a about menu to input a while loop in tkinter app.
106+
107+
# It can use a beautiful GUI also.
108+
# Even validation is left.
109+
# What if string is provided in number? Then?
110+
# What if chars are provided. Then?
111+
# What if a negative number is provided? Then?
112+
# What if a number is provided in alphabets characters? Then?
113+
# Can it a single method have more object in it?
114+
115+
# Also need to perform testing on it.
116+
# EXTREME FORM OF TESTING NEED TO BE PERFORMED ON IT.
117+
# Documentation is also needed.
118+
# Comments are also needed.
119+
# TYPE hints are also needed.
120+
121+
# README.md file is also needed.
122+
## Which will explain the whole project.
123+
### Like how to use the application.
124+
### List down the features in explicit detail.
125+
### How to use different methods and classes.
126+
### It will also a image of the project in working state.
127+
### It will also have a video to the project in working state.
128+
129+
# It should also have .exe and linux executable file.
130+
# It should also be installable into Windows(x86) system and if possible into Linux system also.

0 commit comments

Comments
 (0)