python 格式化输出保留两位小数

def GetOJWords():
    rtval = 0

    try:
        inputstr = input().strip()
        wordlist = inputstr.split()

        if inputstr:
            rtval = (len(inputstr) + 1 - len(wordlist)) / len(wordlist)

    except EOFError:
        rtval = 0

    return rtval
if __name__ == "__main__":
    rtval = GetOJWords()
    print("%.2f" % rtval)

你可能感兴趣的:(Python学习)