Using isdigit for floats?

前端 未结 8 1153
故里飘歌
故里飘歌 2020-12-05 09:59
a = raw_input(\'How much is 1 share in that company? \')

while not a.isdigit():
    print(\"You need to write a number!\\n\")
    a = raw_input(\'How much is 1 shar         


        
8条回答
  •  天命终不由人
    2020-12-05 10:42

    s = '12.32'
    if s.replace('.', '').replace('-', '').isdigit():
        print(float(s))
    

    Note that this will work for negative floats as well.

提交回复
热议问题