0

I use this loop to extract integers, what changes should I make to this loop which will accept decimal numbers. Here inputn is a string:

def numberseeker():
global i, inputn, number, num
while i < len(inputn):
    if inputn[i].isalnum() is True:
        num = float(inputn[i])
        if inputn[i] == 0:
            number += num
        else:
            number = (number * 10) + num
        i += 1
    elif inputn[i].isalnum() is False:
        ope = inputn[i]
        operator(ope)
        break
0

1 Answer 1

0

Since inputn is a string, what's your meaning of this statement? ... if inputn[i] == 0: ...

Because inputn[i] is a char, not an integer, so inputn[i] == 0 will always be false. Even this line doesn't make sense, your original codes still could work correctly. But it's still better to change it to only one line: number = (number * 10) + num

1
  • Thanks for the suggestion. Done
    – shreydan
    Commented Aug 25, 2016 at 13:25

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.