1.统计列表中正数和负数的数量a = [1,3,5,7,0,-1,-9,-4,-5,8]b = []c = []for i in a : if i>0: b.append(i) elif i<0: c.append(i) else: pass print (len(b)) print (len(c))##打印函数在for循环内,输出的结果是 10203040404###打印函数放在if语句外 a = [1,3,5,7,0,-1,-9,-4,-5,8]b = []c = []for i in a
一,如果我们将异常而不影响循环,如下代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace trycatch { class Program { static void Main(string[] args) { //将异常写在循环外,出现异常循环终止 try { Console.WriteLi