python求数字位数的方法

第一种:
利用str()函数将数字转化成字符串,再利用len()函数判断位长。

  1 a=Int(raw_input("the number you want type in:")
  2 b=len(str(a))
  3 print b

第二种:
利用除10取商,通过循环次数判断位数。

  1 c=0
  2 a=int(raw_input("the number you want type in:"))
  3 while a!=0:
  4       a=a/10
  5       c +=1
  6 print c
posted @ 2016-12-05 11:29  Zhong_Leo  阅读(20140)  评论(0编辑  收藏  举报