Pat乙级1024题——科学计数法(Python)

测试结果为满分

def sciCount():
    input = raw_input()
    inputList = []
    for i in range(len(input)):
        inputList.append(input[i])
    eIndex = inputList.index('E')
    sciNum = int(input[eIndex+2:])
    numList = inputList[0:eIndex]
    if inputList[eIndex + 1] == '+':
        numList.remove('.')
        if (eIndex - 3) > sciNum:
            numList.insert(2+sciNum, '.')
        else:
            for i in range(sciNum - eIndex + 3):
                numList.append('0')
    elif inputList[eIndex + 1] == '-':
        numList.remove('.')
        for i in range(sciNum):
            numList.insert(1, '0')
        numList.insert(2, '.')
    result = ''
    for i in range(0, len(numList)):
        if i == 0 and numList[i] == '+':
            continue
        result = result + str(numList[i])
    print result
if __name__ == '__main__':
    sciCount()

你可能感兴趣的:(python,PAT)