统计输入字符串中整数的个数
作者:互联网
1 #统计输入字符串中整数的个数 ----字符与字符之间算一个整数 2 deal = input("please input :") 3 count = 0 4 Deal = deal.rstrip() 5 while (Deal.isalpha() == False ): #筛选出带有数字的字符串 6 for i in range(len(Deal)): 7 if Deal[0].isalpha() == False: #全字母为true,此处用于判断该位是否为数字 8 count = 1 9 if i+1 < len(Deal): 10 if Deal[i].isalpha() == True and Deal[i+1].isalpha() == False: 11 count += 1 12 break 13 else: 14 count = 0 15 print("该字符串共有%d个整数"%count)
标签:count,False,Deal,个数,整数,isalpha,字符串 来源: https://www.cnblogs.com/mmuxu/p/10925280.html