It doesn't work because the int
conversion works only on the string image of an integer numeral. int("1")
would work.
Python does not have a built-in function to convert text strings to numbers. You will need to provide that with some sort of conversion function of your own. In the restricted example you gave, it's simply a matter of
if in2 = "one":
in2 = 1
However, you seem to want a more general solution. There are programs you can look up for converting number phrases to integers in general. For now, you may want simply a look-up table; a dict
works well for this.
str_to_int = {
"one": 1, "two": 2, "three":3, # Continue as far as you need
}
Now, you can do something such as
if in2 in str_to_int:
in2 = str_to_int[in2]
This is still awkward programming, as it does very little for error cases, and you've used one variable for two distinct purposes -- neither of which is apparent from its name. However, fixing all of those problems would involve an overhaul, better done on your own time.