From 9beb720e4891cbf76716a472b301ef9301e35539 Mon Sep 17 00:00:00 2001 From: SDiHALF Date: Wed, 28 Jan 2026 01:10:55 +0530 Subject: [PATCH 01/16] Update AREA OF TRIANGLE.py --- AREA OF TRIANGLE.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/AREA OF TRIANGLE.py b/AREA OF TRIANGLE.py index 2aae5b0d645..db9b04a5a78 100644 --- a/AREA OF TRIANGLE.py +++ b/AREA OF TRIANGLE.py @@ -1,17 +1,20 @@ -# Python Program to find the area of triangle -# calculates area of traingle in efficient way!! -a = 5 -b = 6 -c = 7 +def get_valid_side(prompt:str): + while True: + try: + value = float(input(prompt)) + if value <=0: + print("Side must be positive") + continue + return value + except ValueError: + print("Invalid Input") -# Uncomment below to take inputs from the user -# a = float(input('Enter first side: ')) -# b = float(input('Enter second side: ')) -# c = float(input('Enter third side: ')) -# calculate the semi-perimeter -s = (a + b + c) / 2 +a = get_valid_side("Enter side 1: ") +b = get_valid_side("Enter side 2: ") +c = get_valid_side("Enter side 3: ") -# calculate the area -area = (s * (s - a) * (s - b) * (s - c)) ** 0.5 +semi_perimeter = (a + b + c) / 2 + +area = sqrt((s * (s - a) * (s - b) * (s - c))) print("The area of the triangle is %0.2f" % area) From 0c2fcfa4527851634e061590b9d2c448dd2bfd72 Mon Sep 17 00:00:00 2001 From: Derderderr Date: Wed, 11 Feb 2026 23:56:55 +0800 Subject: [PATCH 02/16] Update scrap_file.py Add timeout and streaming for large files, and some other changes --- scrap_file.py | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/scrap_file.py b/scrap_file.py index 7655e792cbe..aab6e2a2e08 100644 --- a/scrap_file.py +++ b/scrap_file.py @@ -6,33 +6,23 @@ import requests -# Function for download file parameter taking as url - +def download(url, filename): + try: + with requests.get(url, stream=True, timeout=10) as response: + response.raise_for_status() # Raises error for 4xx/5xx -def download(url): - f = open( - "file_name.jpg", "wb" - ) # opening file in write binary('wb') mode with file_name.ext ext=extension - f.write(requests.get(url).content) # Writing File Content in file_name.jpg - f.close() - print("Succesfully Downloaded") + with open(filename, "wb") as file: + for chunk in response.iter_content(chunk_size=8192): + if chunk: + file.write(chunk) + print(f"Successfully downloaded: {filename}") -# Function is do same thing as method(download) do,but more strict -def download_2(url): - try: - response = requests.get(url) - except Exception: - print("Failed Download!") - else: - if response.status_code == 200: - with open("file_name.jpg", "wb") as f: - f.write(requests.get(url).content) - print("Succesfully Downloaded") - else: - print("Failed Download!") + except requests.exceptions.RequestException as e: + print(f"Download failed: {e}") -url = "https://avatars0.githubusercontent.com/u/29729380?s=400&v=4" # URL from which we want to download +# Example usage +url = "https://avatars0.githubusercontent.com/u/29729380?s=400&v=4" +download(url, "avatar.jpg") -download(url) From 7f439debca1bb76f2ef359190e090b38ada7ad24 Mon Sep 17 00:00:00 2001 From: Derderderr Date: Thu, 12 Feb 2026 00:02:05 +0800 Subject: [PATCH 03/16] Refractor add welcome and start_game as seperated function --- blackjack.py | 164 +++++++++++++++++++++++++-------------------------- 1 file changed, 81 insertions(+), 83 deletions(-) diff --git a/blackjack.py b/blackjack.py index b2386ff7828..05f25e1f215 100644 --- a/blackjack.py +++ b/blackjack.py @@ -4,104 +4,102 @@ deck = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11] * 4 -random.shuffle(deck) - -print( - " ********************************************************** " -) -print( - " Welcome to the game Casino - BLACK JACK ! " -) -print( - " ********************************************************** " -) - -d_cards = [] # Initialising dealer's cards -p_cards = [] # Initialising player's cards - -while len(d_cards) != 2: - random.shuffle(deck) - d_cards.append(deck.pop()) - if len(d_cards) == 2: - print("The cards dealer has are X ", d_cards[1]) - -# Displaying the Player's cards -while len(p_cards) != 2: - random.shuffle(deck) - p_cards.append(deck.pop()) - if len(p_cards) == 2: - print("The total of player is ", sum(p_cards)) - print("The cards Player has are ", p_cards) - -if sum(p_cards) > 21: - print("You are BUSTED !\n **************Dealer Wins !!******************\n") - exit() -if sum(d_cards) > 21: +def welcome(): + print( + " ********************************************************** " + ) + print( + " Welcome to the game Casino - BLACK JACK ! " + ) print( - "Dealer is BUSTED !\n ************** You are the Winner !!******************\n" + " ********************************************************** " ) - exit() -if sum(d_cards) == 21: - print("***********************Dealer is the Winner !!******************") - exit() -if sum(d_cards) == 21 and sum(p_cards) == 21: - print("*****************The match is tie !!*************************") - exit() +def start_game(): + random.shuffle(deck) + d_cards = [] + p_cards = [] -def dealer_choice(): - if sum(d_cards) < 17: - while sum(d_cards) < 17: - random.shuffle(deck) - d_cards.append(deck.pop()) + # Dealer initial cards + while len(d_cards) != 2: + random.shuffle(deck) + d_cards.append(deck.pop()) + if len(d_cards) == 2: + print("The cards dealer has are X ", d_cards[1]) + + # Player initial cards + while len(p_cards) != 2: + random.shuffle(deck) + p_cards.append(deck.pop()) + if len(p_cards) == 2: + print("The total of player is ", sum(p_cards)) + print("The cards Player has are ", p_cards) - print("Dealer has total " + str(sum(d_cards)) + "with the cards ", d_cards) + if sum(p_cards) > 21: + print("You are BUSTED !\n **************Dealer Wins !!******************\n") + return - if sum(p_cards) == sum(d_cards): - print("***************The match is tie !!****************") - exit() + if sum(d_cards) > 21: + print( + "Dealer is BUSTED !\n ************** You are the Winner !!******************\n" + ) + return + + if sum(d_cards) == 21 and sum(p_cards) == 21: + print("*****************The match is tie !!*************************") + return if sum(d_cards) == 21: - if sum(p_cards) < 21: - print("***********************Dealer is the Winner !!******************") - elif sum(p_cards) == 21: - print("********************There is tie !!**************************") - else: - print("***********************Dealer is the Winner !!******************") + print("***********************Dealer is the Winner !!******************") + return - elif sum(d_cards) < 21: - if sum(p_cards) < 21 and sum(p_cards) < sum(d_cards): - print("***********************Dealer is the Winner !!******************") - if sum(p_cards) == 21: - print("**********************Player is winner !!**********************") - if sum(p_cards) < 21 and sum(p_cards) > sum(d_cards): - print("**********************Player is winner !!**********************") + def dealer_choice(): + if sum(d_cards) < 17: + while sum(d_cards) < 17: + random.shuffle(deck) + d_cards.append(deck.pop()) + + print("Dealer has total " + str(sum(d_cards)) + " with the cards ", d_cards) - else: - if sum(p_cards) < 21: + if sum(p_cards) == sum(d_cards): + print("***************The match is tie !!****************") + return + + if sum(d_cards) > 21: print("**********************Player is winner !!**********************") - elif sum(p_cards) == 21: + return + + if sum(d_cards) > sum(p_cards): + print("***********************Dealer is the Winner !!******************") + else: print("**********************Player is winner !!**********************") + + # Player turn + while sum(p_cards) < 21: + k = input("Want to hit or stay?\n Press 1 for hit and 0 for stay ") + + if k == "1": + random.shuffle(deck) + p_cards.append(deck.pop()) + print("You have a total of " + str(sum(p_cards)) + " with the cards ", p_cards) + + if sum(p_cards) > 21: + print("*************You are BUSTED !*************\n Dealer Wins !!") + return + + if sum(p_cards) == 21: + print( + "*******************You are the Winner !!*****************************" + ) + return else: - print("***********************Dealer is the Winner !!******************") + dealer_choice() + break -while sum(p_cards) < 21: - k = input("Want to hit or stay?\n Press 1 for hit and 0 for stay ") - if k == 1: - random.shuffle(deck) - p_cards.append(deck.pop()) - print("You have a total of " + str(sum(p_cards)) + " with the cards ", p_cards) - if sum(p_cards) > 21: - print("*************You are BUSTED !*************\n Dealer Wins !!") - if sum(p_cards) == 21: - print( - "*******************You are the Winner !!*****************************" - ) - - else: - dealer_choice() - break +# Run Game +welcome() +start_game() From 131ed9d3c4e8c569bcd2e9689d0a72ff6303b696 Mon Sep 17 00:00:00 2001 From: Derderderr Date: Thu, 12 Feb 2026 00:07:27 +0800 Subject: [PATCH 04/16] Rafractor to much simplier logic and Add check input --- To print series 1,12,123,1234......py | 57 +++++++-------------------- 1 file changed, 15 insertions(+), 42 deletions(-) diff --git a/To print series 1,12,123,1234......py b/To print series 1,12,123,1234......py index cc192eed3eb..d62d34aee3b 100644 --- a/To print series 1,12,123,1234......py +++ b/To print series 1,12,123,1234......py @@ -1,47 +1,20 @@ -# master -def num(a): - # initialising starting number +def print_pattern(rows: int) -> None: + for i in range(1, rows + 1): + print("".join(str(j) for j in range(1, i + 1))) - num = 1 - # outer loop to handle number of rows +def start(): + while True: + try: + n = int(input("Enter number of rows: ")) + if n < 1: + print("Invalid value, enter a positive integer.") + continue + break + except ValueError: + print("Invalid input, please enter a number.") - for i in range(0, a): - # re assigning num + print_pattern(n) - num = 1 - # inner loop to handle number of columns - - # values changing acc. to outer loop - - for k in range(0, i + 1): - # printing number - - print(num, end=" ") - - # incrementing number at each column - - num = num + 1 - - # ending line after each row - - print("\r") - - -# Driver code - -a = 5 - -num(a) -# ======= -# 1-12-123-1234 Pattern up to n lines - -n = int(input("Enter number of rows: ")) - -for i in range(1, n + 1): - for j in range(1, i + 1): - print(j, end="") - print() - -# master +start() From f6731910166a14db1915bec03e36a754293b5f3a Mon Sep 17 00:00:00 2001 From: Derderderr Date: Thu, 12 Feb 2026 23:59:35 +0800 Subject: [PATCH 05/16] Fix --- Multiply.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Multiply.py b/Multiply.py index c8e1b52228f..8d4121cfe56 100644 --- a/Multiply.py +++ b/Multiply.py @@ -1,4 +1,8 @@ def product(a, b): + # Handle negative values + if b < 0: + return -product(a, -b) + if a < b: return product(b, a) elif b != 0: @@ -9,4 +13,4 @@ def product(a, b): a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) -print("Product is: ", product(a, b)) +print("Product is:", product(a, b)) From 5400fba10e06d0b070a74c174c69bd353ea05d21 Mon Sep 17 00:00:00 2001 From: derek-han <68950075+derek-han@users.noreply.github.com> Date: Sun, 15 Feb 2026 11:09:48 +0800 Subject: [PATCH 06/16] Add-Derderderr --- Collatz Sequence/Collaze-Visualize.py | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Collatz Sequence/Collaze-Visualize.py diff --git a/Collatz Sequence/Collaze-Visualize.py b/Collatz Sequence/Collaze-Visualize.py new file mode 100644 index 00000000000..8431794e843 --- /dev/null +++ b/Collatz Sequence/Collaze-Visualize.py @@ -0,0 +1,74 @@ +import time +import matplotlib.pyplot as plt + +def collatz_sequence(n): + """Generate the Collatz sequence for n.""" + steps = [n] + while n != 1: + n = n // 2 if n % 2 == 0 else 3 * n + 1 + steps.append(n) + return steps + + +def visualize(sequence, title="Collatz Sequence"): + plt.clf() + plt.plot(sequence, marker='o') + plt.title(title) + plt.xlabel("Step") + plt.ylabel("Value") + plt.yscale("log") # makes visualization MUCH nicer + plt.grid(True) + plt.pause(0.01) + + +def auto_mode(interval): + print("\nAuto mode started.") + print("Press SPACE in the plot window to stop.\n") + + plt.ion() + stop = False + + def on_key(event): + nonlocal stop + if event.key == ' ': + stop = True + + fig = plt.figure() + fig.canvas.mpl_connect("key_press_event", on_key) + + n = 1 + while not stop: + seq = collatz_sequence(n) + visualize(seq, f"Collatz Sequence for n = {n}") + n += 1 + time.sleep(interval) + + plt.ioff() + plt.show() + print("Auto mode stopped.") + + +# --- Main Program --- +try: + num = int(input("Enter a positive integer (or -1 for auto mode): ")) + + if num == -1: + interval = float(input("Enter step interval time (seconds): ")) + auto_mode(interval) + + elif num <= 0: + print("Please enter a positive number greater than 0.") + + else: + seq = collatz_sequence(num) + print("\nCollatz sequence:") + for i, value in enumerate(seq, start=1): + print(f"Step {i}: {value}") + + plt.ion() + visualize(seq, f"Collatz Sequence for n = {num}") + plt.ioff() + plt.show() + +except ValueError: + print("Invalid input! Please enter a valid number.") From 58b3142b5541e03b366e6727c3f3a4cb99f817e3 Mon Sep 17 00:00:00 2001 From: Derderderr Date: Sun, 15 Feb 2026 23:48:33 +0800 Subject: [PATCH 07/16] Update Calculate resistance.py Allow float --- Calculate resistance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Calculate resistance.py b/Calculate resistance.py index 06dff0b5723..37af01f64dd 100644 --- a/Calculate resistance.py +++ b/Calculate resistance.py @@ -7,8 +7,8 @@ def res(R1, R2): return 0 -Resistance1 = int(input("Enter R1 : ")) -Resistance2 = int(input("Enter R2 : ")) +Resistance1 = float(input("Enter R1 : ")) +Resistance2 = float(input("Enter R2 : ")) option = input("Enter series or parallel :") print("\n") R = res(Resistance1, Resistance2) From bd5e214d9c298b98348e3f9632505cc0efacdce0 Mon Sep 17 00:00:00 2001 From: Aljubina Date: Mon, 16 Feb 2026 10:36:53 +0530 Subject: [PATCH 08/16] renamed the variables --- calci.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/calci.py b/calci.py index 21d9ace5233..e988d10638e 100644 --- a/calci.py +++ b/calci.py @@ -1,4 +1,4 @@ -a = int(input("enter first value")) -b = int(input("enter second value")) -add = a + b +First = int(input("enter first value")) +Second = int(input("enter second value")) +add = First + Second print(add) From ae285de55863f94f70c7b1568ea5cbdb8cff39e7 Mon Sep 17 00:00:00 2001 From: 2007aman Date: Thu, 19 Feb 2026 17:33:59 +0530 Subject: [PATCH 09/16] improved dice class logic and added validation --- dice.py | 64 ++++++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/dice.py b/dice.py index a2e5c12f99b..7f05f277683 100644 --- a/dice.py +++ b/dice.py @@ -1,45 +1,39 @@ -# Script Name : dice.py -# Author : Craig Richards -# Created : 05th February 2017 -# Last Modified : -# Version : 1.0 - -# Modifications : - -# Description : This will randomly select two numbers, -# like throwing dice, you can change the sides of the dice if you wish - import random - -class Die(object): - # A dice has a feature of number about how many sides it has when it's - # established,like 6. - def __init__(self): - self.sides = 6 - - """because a dice contains at least 4 planes. - So use this method to give it a judgement when you need - to change the instance attributes. +class Die: + """ + A class used to represent a multi-sided die. + + Attributes: + sides (int): The number of sides on the die (default is 6). """ - def set_sides(self, sides_change): - if sides_change >= 4: - if sides_change != 6: - print("change sides from 6 to ", sides_change, " !") + def __init__(self, sides=6): + """Initializes the die. Defaults to 6 sides if no value is provided.""" + self.sides = 6 # Internal default + self.set_sides(sides) + + def set_sides(self, num_sides): + """ + Validates and sets the number of sides. + A physical die must have at least 4 sides. + """ + if isinstance(num_sides, int) and num_sides >= 4: + if num_sides != self.sides: + print(f"Changing sides from {self.sides} to {num_sides}!") else: - # added else clause for printing a message that sides set to 6 - print("sides set to 6") - self.sides = sides_change + print(f"Sides already set to {num_sides}.") + self.sides = num_sides else: - print("wrong sides! sides set to 6") + print(f"Invalid input: {num_sides}. Keeping current value: {self.sides}") def roll(self): + """Returns a random integer between 1 and the number of sides.""" return random.randint(1, self.sides) - -d = Die() -d1 = Die() -d.set_sides(4) -d1.set_sides(4) -print(d.roll(), d1.roll()) +# --- Example Usage --- +if __name__ == "__main__": + d1 = Die(4) # Initialize directly with 4 sides + d2 = Die(12) # A Dungeons & Dragons classic + + print(f"Roll Result: D{d1.sides} -> {d1.roll()}, D{d2.sides} -> {d2.roll()}") From cb894596fb20308e2d6ab0ced9d643576db8e77a Mon Sep 17 00:00:00 2001 From: 2007aman Date: Tue, 24 Feb 2026 20:46:35 +0530 Subject: [PATCH 10/16] updated the logic in Armstrong_number.py file --- Armstrong_number.py | 45 +++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/Armstrong_number.py b/Armstrong_number.py index 9c73522992c..a5b02293aaa 100644 --- a/Armstrong_number.py +++ b/Armstrong_number.py @@ -1,30 +1,19 @@ -""" -In number theory, a narcissistic number (also known as a pluperfect digital invariant (PPDI), an Armstrong number (after Michael F. Armstrong) or a plus perfect number), -in a given number base b, is a number that is the total of its own digits each raised to the power of the number of digits. -Source: https://en.wikipedia.org/wiki/Narcissistic_number -NOTE: -this scripts only works for number in base 10 -""" +def is_armstrong_number(number: str) -> bool: + """Check if a number (as a string) is a narcissistic/Armstrong number.""" + # Logic: Get the exponent (number of digits) + exponent = len(number) + + # Logic: Sum each digit raised to the power in a single line + # This uses a generator, which is memory efficient. + total = sum(int(digit) ** exponent for digit in number) + + # Return the boolean result instead of printing + return total == int(number) +# --- Main execution --- +user_input = input("Enter the number: ") -def is_armstrong_number(number: str): - total: int = 0 - exp: int = len( - number - ) # get the number of digits, this will determinate the exponent - - digits: list[int] = [] - for digit in number: - digits.append(int(digit)) # get the single digits - for x in digits: - total += x**exp # get the power of each digit and sum it to the total - - # display the result - if int(number) == total: - print(number, "is an Armstrong number") - else: - print(number, "is not an Armstrong number") - - -number = input("Enter the number : ") -is_armstrong_number(number) +if is_armstrong_number(user_input): + print(f"{user_input} is an Armstrong number") +else: + print(f"{user_input} is not an Armstrong number") From 3ca6330192b3fa2ca4bbe6aa6c0c190be0351960 Mon Sep 17 00:00:00 2001 From: 2007aman Date: Mon, 9 Mar 2026 05:36:39 +0530 Subject: [PATCH 11/16] added the read file logic in the program in 12 line one and also correct some file names to easy --- 1-file_handle | 1 + 1 file changed, 1 insertion(+) create mode 160000 1-file_handle diff --git a/1-file_handle b/1-file_handle new file mode 160000 index 00000000000..c9283ce68a8 --- /dev/null +++ b/1-file_handle @@ -0,0 +1 @@ +Subproject commit c9283ce68a8ff170e24082e22ed598da549c49ae From d8d6ac84f2f5b3b94a469f12b229677781ec0908 Mon Sep 17 00:00:00 2001 From: "raktimunreal4@gmail.com" Date: Sun, 22 Mar 2026 18:48:30 +0530 Subject: [PATCH 12/16] Create numbername.py --- NumberToNumberName/numbername.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 NumberToNumberName/numbername.py diff --git a/NumberToNumberName/numbername.py b/NumberToNumberName/numbername.py new file mode 100644 index 00000000000..b7fee0ad802 --- /dev/null +++ b/NumberToNumberName/numbername.py @@ -0,0 +1,5 @@ +# A program to write a number in words +# Eg: +# 61893: Sixty One Thousand Eight Hundred Ninety Three + +__import__('os').system('cls') From d155bfe581523685d198052669e72ffd8433e7a7 Mon Sep 17 00:00:00 2001 From: "raktimunreal4@gmail.com" Date: Sun, 22 Mar 2026 18:49:07 +0530 Subject: [PATCH 13/16] Define color variables --- NumberToNumberName/numbername.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NumberToNumberName/numbername.py b/NumberToNumberName/numbername.py index b7fee0ad802..bff7feb2b96 100644 --- a/NumberToNumberName/numbername.py +++ b/NumberToNumberName/numbername.py @@ -3,3 +3,9 @@ # 61893: Sixty One Thousand Eight Hundred Ninety Three __import__('os').system('cls') + + +Y = "\033[38;2;255;200;0m" +W = "\033[38;2;212;212;212;0m" +B = "\033[38;2;108;180;238m;0m" + From 2874164298d72463c02f51edde8696b98156b4ef Mon Sep 17 00:00:00 2001 From: "raktimunreal4@gmail.com" Date: Sun, 22 Mar 2026 18:50:38 +0530 Subject: [PATCH 14/16] Map digits, specific numbers and placevalues --- NumberToNumberName/numbername.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/NumberToNumberName/numbername.py b/NumberToNumberName/numbername.py index bff7feb2b96..7a842de3d5b 100644 --- a/NumberToNumberName/numbername.py +++ b/NumberToNumberName/numbername.py @@ -9,3 +9,29 @@ W = "\033[38;2;212;212;212;0m" B = "\033[38;2;108;180;238m;0m" +numDict = { + 1 : "One", 2 : "Two", 3 : "Three", 4 : "Four", 5 : "Five", + 6 : "Six", 7 : "Seven", 8 : "Eight", 9 : "Nine", 10 : "Ten", + 11 : "Eleven", 12 : "Twelve", 13 : "Thirteen", 14 : "Fourteen", 15 : "Fifteen", + 16 : "Sixteen", 17 : "Seventeen", 18 : "Eighteen", 19 : "Ninteen", 20 : "Twenty", + 30 : "Thirty", 40 : "Forty", 50 : "Fifty", 60 : "Sixty", 70 : "Seventy", + 80 : "Eighty", 90 : "Ninety" +} + +digits = { + "1" : "One", "2" : "Two", "3" : "Three", "4" : "Four", "5" : "Five", + "6" : "Six", "7" : "Seven", "8" : "Eight", "9" : "Nine", "0" : "Zero" +} + +placeValueDict = { + 1 : "", + 2 : "Thousand", + 3 : "Million", + 4 : "Billion", + 5 : "Trillion", + 6 : "Quadrillion", + 7 : "Quintillion", + 8 : "Sextillion", + 9 : "Septilion", + 10 : "Octillion" +} From 4d2780d68bc6ed05889691df44883919026a8d75 Mon Sep 17 00:00:00 2001 From: "raktimunreal4@gmail.com" Date: Sun, 22 Mar 2026 18:53:29 +0530 Subject: [PATCH 15/16] Taking input and validating it --- NumberToNumberName/numbername.py | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/NumberToNumberName/numbername.py b/NumberToNumberName/numbername.py index 7a842de3d5b..5ef47e41b9d 100644 --- a/NumberToNumberName/numbername.py +++ b/NumberToNumberName/numbername.py @@ -35,3 +35,43 @@ 9 : "Septilion", 10 : "Octillion" } + +print("Maximum Input: 999,999,999,999,999,999,999,999,999,999") +print("Minimum Input: -999,999,999,999,999,999,999,999,999,999\n") + +isNegative = False + +while True: + num = input(f"Enter a number: {Y}") + print(f"{W}", end="") + + try: + splittedNum = num.split(".") + + splittedNum[0] = splittedNum[0].replace(" ", "") + if len(splittedNum) == 2: + splittedNum[1] = splittedNum[1].replace(" ", "") + splittedNum[1] = splittedNum[1].rstrip("0") + + if splittedNum[1] == "": + splittedNum.remove("") + + num = int(splittedNum[0]) + + if len(splittedNum) == 1: + placeholder = splittedNum[0] + placeholder = int(placeholder) + else: + placeholder = splittedNum[0] + "." + splittedNum[1] + placeholder = float(placeholder) + + if num >= 1000000000000000000000000000000 or num <= -1000000000000000000000000000000: + print("Input out of range\n") + else: + if num < 0: + isNegative = True + num = num * (-1) + break + except ValueError or EOFError: + print("Invalid Input\n") + From 284115019d25f53ead9cd745e0e1fc0d2dfc2ac6 Mon Sep 17 00:00:00 2001 From: "raktimunreal4@gmail.com" Date: Sun, 22 Mar 2026 18:54:38 +0530 Subject: [PATCH 16/16] Forming and printing the number name --- NumberToNumberName/numbername.py | 64 ++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/NumberToNumberName/numbername.py b/NumberToNumberName/numbername.py index 5ef47e41b9d..8eae393db6b 100644 --- a/NumberToNumberName/numbername.py +++ b/NumberToNumberName/numbername.py @@ -9,6 +9,10 @@ W = "\033[38;2;212;212;212;0m" B = "\033[38;2;108;180;238m;0m" +groupedList = [] +name = "" +nameList = [] + numDict = { 1 : "One", 2 : "Two", 3 : "Three", 4 : "Four", 5 : "Five", 6 : "Six", 7 : "Seven", 8 : "Eight", 9 : "Nine", 10 : "Ten", @@ -75,3 +79,63 @@ except ValueError or EOFError: print("Invalid Input\n") + +if num == 0: + print(f"0 in words is: {Y}Zero{W}") +else: + while num > 0: + groupedList.append(num % 1000) + num //= 1000 + + groupedList.reverse() + + for i in groupedList: + if i != 0: + if i >= 100: + name = name + numDict[int(i/100)] + " Hundred" + i = i % 100 + + if i >= 20: + if name == "": + name = name + numDict[i - (i % 10)] + else: + name = name + " " + numDict[i - (i % 10)] + + i = i % 10 + elif i >= 10: + if name == "": + name = name + numDict[i] + else: + name = name + " " + numDict[i] + + i = i % 10 + + if i != 0: + if name == "": + name = name + numDict[i] + else: + name = name + " " + numDict[i] + + nameList.append(name) + name = "" + else: + nameList.append("") + + for i in range(len(groupedList)): + if nameList[i] != "": + name = name + nameList[i] + " " + placeValueDict[len(groupedList) - i] + " " + + name = name.rstrip() + + if len(splittedNum) == 2 and splittedNum[1] != "": + name = name + f" {B}Point{Y}" + + for i in splittedNum[1]: + name = name + " " + digits[i] + + print(f"{W}", end="") + + if isNegative == False: + print(f"\n{placeholder} in words is: {Y}{name}{W}") + else: + print(f"\n{placeholder} in words is: {Y}Minus {name}{W}")