如何添加超过1dp的检查

时间:2016-09-22 23:30:18

标签: python python-3.4

我想停止小数输入超过00.0(1dp)。 所以他们输入一个数字,但我希望它以1dp为百分比(例如44.7%或7.5%) 这是代码:

print(aCounter)

1 个答案:

答案 0 :(得分:0)

while nameSave <=0 or nameSave >99:
    while True:
        try:
            nameSave = float(input("Enter % Savings (Between 1-99%): "))
            check = str(nameSave)
            if (check[1] == '.' and len(check) > 3) or len(check) > 4:
                print("Needs to be precise to 1 decimal point")

            break
        except:
            print("Needs to be a number ")