Using isdigit for floats?

前端 未结 8 1168
故里飘歌
故里飘歌 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:45

    Use regular expressions.

    import re
    
    p = re.compile('\d+(\.\d+)?')
    
    a = raw_input('How much is 1 share in that company? ')
    
    while p.match(a) == None:
        print "You need to write a number!\n"
        a = raw_input('How much is 1 share in that company? ')
    

提交回复
热议问题