I am currently having a problem when just reading the number from a string. I somehow does not receive the proper value. I need to distinguish between 1 and 2 numbered strings and need to account for it. My Output looks like the following:
9 1
but it should be:
9 10
def StringToNumber(Period):
if Period[-1:] == "D":
period_unit = int(Period[:1])
elif Period[-1:] == 'M':
period_unit = int(Period[:1])
elif Period[-1:] == 'W':
period_unit = int(Period[:1])
elif Period[-1:] == 'Y':
period_unit = int(Period[:1])
elif Period == '':
period_unit = int(0)
else:
raise Exception('Problems')
return period_unit
years_string1 = '9Y'
years_string2 = '10Y'
years_number1 = StringToNumber(years_string1)
years_number2 = StringToNumber(years_string2)
print(years_number1)
print(years_number2)