-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2063 from NitkarshChourasia/testing
add: some more feature packed applications.
- Loading branch information
Showing
3 changed files
with
60 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from word2number import w2n | ||
|
||
# ? word2number then w2n then .word_to_num? So, library(bunch of modules) then module then method(function)???! | ||
# return w2n.word_to_num(input_value) | ||
|
||
|
||
# TODO: Instead of rounding at the destination, round at the source. | ||
# Reason: As per the program need, I don't want a functionality to round or not round the number, based on the requirement, I always want to round the number. | ||
#! Will see it tomorrow. | ||
|
||
|
||
class DetermineSign: | ||
def __init__(self, num=None): | ||
if num is None: | ||
self.get_number() | ||
else: | ||
self.num = round(self.convert_to_float(num), 1) | ||
|
||
# TODO: Word2number | ||
|
||
# Need to further understand this. | ||
# ? NEED TO UNDERSTAND THIS. FOR SURETY. | ||
def convert_to_float(self, input_value): | ||
try: | ||
return float(input_value) | ||
except ValueError: | ||
try: | ||
return w2n.word_to_num(input_value) | ||
except ValueError: | ||
raise ValueError( | ||
"Invalid input. Please enter a number or a word representing a number." | ||
) | ||
|
||
# Now use this in other methods. | ||
|
||
def get_number(self): | ||
self.input_value = format(float(input("Enter a number: ")), ".1f") | ||
self.num = round(self.convert_to_float(self.input_value), 1) | ||
return self.num | ||
# Do I want to return the self.num? | ||
# I think I have to just store it as it is. | ||
|
||
def determine_sign(self): | ||
if self.num > 0: | ||
return "Positive number" | ||
elif self.num < 0: | ||
return "Negative number" | ||
else: | ||
return "Zero" | ||
|
||
def __repr__(self): | ||
return f"Number: {self.num}, Sign: {self.determine_sign()}" | ||
|
||
|
||
if __name__ == "__main__": | ||
number1 = DetermineSign() | ||
print(number1.determine_sign()) | ||
|
||
|
||
# !Incomplete. |