Skip to content

Commit 4d2780d

Browse files
committed
Taking input and validating it
1 parent 2874164 commit 4d2780d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

NumberToNumberName/numbername.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,43 @@
3535
9 : "Septilion",
3636
10 : "Octillion"
3737
}
38+
39+
print("Maximum Input: 999,999,999,999,999,999,999,999,999,999")
40+
print("Minimum Input: -999,999,999,999,999,999,999,999,999,999\n")
41+
42+
isNegative = False
43+
44+
while True:
45+
num = input(f"Enter a number: {Y}")
46+
print(f"{W}", end="")
47+
48+
try:
49+
splittedNum = num.split(".")
50+
51+
splittedNum[0] = splittedNum[0].replace(" ", "")
52+
if len(splittedNum) == 2:
53+
splittedNum[1] = splittedNum[1].replace(" ", "")
54+
splittedNum[1] = splittedNum[1].rstrip("0")
55+
56+
if splittedNum[1] == "":
57+
splittedNum.remove("")
58+
59+
num = int(splittedNum[0])
60+
61+
if len(splittedNum) == 1:
62+
placeholder = splittedNum[0]
63+
placeholder = int(placeholder)
64+
else:
65+
placeholder = splittedNum[0] + "." + splittedNum[1]
66+
placeholder = float(placeholder)
67+
68+
if num >= 1000000000000000000000000000000 or num <= -1000000000000000000000000000000:
69+
print("Input out of range\n")
70+
else:
71+
if num < 0:
72+
isNegative = True
73+
num = num * (-1)
74+
break
75+
except ValueError or EOFError:
76+
print("Invalid Input\n")
77+

0 commit comments

Comments
 (0)