基础练习No3

如用户输入:1+2或1+ 2或1 + 2,然后进行分割再进行计算。
 1 content = input(‘请输入内容:’) 
 2 content=input('>>>').strip()
 3 con1=content.split('+')
 4 li[]
 5 num=0
 6 for i in con1:
 7     num+=int(i)
 8 print(num)
 9 content=input('>>>').strip()
10 index = content.find("+")
11 a = int(content[0:index])
12 b = int(content[index+1:])
13 print(a + b)
输入一串文字+数字 统计出来数字的个数
1 s = input("请输入:")  # '1234324324fdsaf1fdsaf12'
2 count = 0
3 for i in s:
4     if i.isdigit():
5         count += 1
6 print(count)

 

posted @ 2019-06-14 16:59  WuKongSir  阅读(25)  评论(0)    收藏  举报