I've been working on this for a day or two in order to tell if an input is an integer, float or string.
In short the program is designed to turn every input into a string, loop through each string and check through the list digits. If the string has all digits its an integer, if it has a '.' its a float, and if it has none it's not a number. The obvious flaw is strings containing letters and '.' which would be considered floats in this program.
The end goal for this program is to open text files and see what input is an int, float, or other.
Questions
-Is there any way to further optimize this program
-How can I further modify this program to open text files, read, analyze, and write which input is in which list
First post!!!
#Checks input to see if input is integer, float, or character
integer = []
float = []
not_number = []
digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
input_list = [100, 234, 'random', 5.23, 55.55, 'random2']
for i in input_list:
i = str(i)
length = len(i)
count = 0
marker = 0
for j in i:
for k in digits:
if k == j:
count = count + 1
#k loops through digits to see if j single character
#string input is number
if count == length:
integer.append(i)
marker = 1
#count is equal to length if entire string is integers
if j == '.':
float.append(i)
marker = 1
#Once '.' is found, input is "considered" a float
if marker == 1:
break
else:
not_number.append(i)
#If code above else proves that input is not a number the
#only result is that it isn't a number
print ('Integers: ', integer)
print ('Float: ', float)
print ('Not Numbers', not_number)