I need to make a function that returns the value corresponding to its positional value.
Example:
positional value
Ten in 1234 returns 3
hundred in 1234 returns 2
1 unit of thousand, 2 hundred, 3 ten, 4 unit
I'd tried this:
def positional_value(x):
x=str(x)
numbers=[]
numbers.extend(x)
numbers.reverse()
for index,i in enumerate(numbers):
if index==0:
print(i) #so where x is 1234, Here I can get 4.
With what I tried I just can get the numbers by index. I thought that using a list with the positional values names (unit, ten, hundred, unit of thousand, ...) will help to describe each query to the function.
output example: when you print the function:
1 unit of thousand
2 hundred
3 ten
4 unit
#and goes on when the number is bigger