Python自学笔记(11day)
练习题
#用for循环数出1-2+3-4+99 count=1 sum=0 for count in range(0,100): if count%2==1: sum=sum+count else: sum=sum-2 print(sum)
#使用range打新出100,99,98.....0 count=100 for count in range(100,-1,-1): print(count)
#计算用户输入的内容索引为奇数,并且计算出对应元素数字的个数( count=0 content=input("请输入你所要输入的内容") for i in range(len(content)): if i%2==1 and content[i].isdigit(): count+=1 print(count)
#list=[23,45,77,89,100],小于75放入字典key1下面,大于77放入key2下面 list=[23,45,77,89,100] list1=[] list2=[] dict={} for i in list: if i<75: list1.append(i) else : list2.append(i) dict.setdefault("key1",list1) dict.setdefault("key2",list2) print(dict)
#计算用户输入的内容索引为奇数,并且计算出对应元素数字的个数( count=0 content=input("请输入你所要输入的内容") for i in range(len(content)): if i%2==1 and content[i].isdigit(): count+=1 print(count)