diff --git a/calculatorproject.py b/calculatorproject.py deleted file mode 100644 index 9e335d38c95..00000000000 --- a/calculatorproject.py +++ /dev/null @@ -1,41 +0,0 @@ -# Program make a simple calculator -def add(x, y): - return x + y -def subtract(x, y): - return x - y -def multiply(x, y): - return x * y - -def divide(x, y): - return x / y - - -print("Select operation.") -print("1.Add") -print("2.Subtract") -print("3.Multiply") -print("4.Divide") - -while True: - # Take input from the user - choice = input("Enter choice(1/2/3/4): ") - - # Check if choice is one of the four options - if choice in ('1', '2', '3', '4'): - num1 = float(input("Enter first number: ")) - num2 = float(input("Enter second number: ")) - - if choice == '1': - print(num1, "+", num2, "=", add(num1, num2)) - - elif choice == '2': - print(num1, "-", num2, "=", subtract(num1, num2)) - - elif choice == '3': - print(num1, "*", num2, "=", multiply(num1, num2)) - - elif choice == '4': - print(num1, "/", num2, "=", divide(num1, num2)) - break - else: - print("Invalid Input") diff --git a/environment.yml b/environment.yml new file mode 100644 index 00000000000..a290a698a55 Binary files /dev/null and b/environment.yml differ diff --git a/nitkarshchourasia/determine_sign.py b/nitkarshchourasia/determine_sign.py new file mode 100644 index 00000000000..0bca22148a3 --- /dev/null +++ b/nitkarshchourasia/determine_sign.py @@ -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.