python 3【实战】

 1 list1 = []
 2 print("(Enter -1 finish)")
 3 num = eval(input("Enter :"))
 4 while num!=-1:
 5     list1.append(num)
 6     num = eval(input("Enter a nonegative number:"))
 7 if len(list1)>0:
 8     list1.sort()
 9     print("Min",list1[0])
10     print("Max",list1[-1])
11     print("AVE",sum(list1)/len(list1))
12 else:
13     print("No number")
输入平均数字

 

1 numberOfYears = 0
2 balance = eval(input("Enter initial:"))
3 while balance<1000000:
4     balance+=.04*balance
5     numberOfYears+=1
6 print("In",numberOfYears,"years you will have a million dollars")
复合利率
 1 list1=["one","1","44","two","33","three"]
 2 i=0
 3 foundFlag = False
 4 while i<len(list1):
 5     x = list1[i]
 6     i+=1
 7     if not isinstance(x,int):
 8         continue
 9     if x % 11 == 0:
10         foundFlag = True
11         print(x,"能被11整除")
12 else:
13     print("数组循环完毕")
14 if not foundFlag:
15     print("这个数组里没有")
循环数组直到符合

 

 1 #格式化输出
 2 #print("%s,%s"%("第一个","第二个"))
 3 #print("{0},{1}".format("第一个","第二个"))
 4 pop = 300000
 5 print("{0:10} {1}".format("year","population"))
 6 for year in range(2014,2019):
 7     print("{0:<10d} {1:,d}".format(year,round(pop)))
 8     pop+=0.03*pop
 9    
10  
格式化输出
1 for m in range(1,6):
2     for n in range(1,6):
3         print(m,'x',n,'=',m*n,"\t",end="")
4     print()    
乘法表

 

posted @ 2018-03-20 20:42  Justice-V  阅读(87)  评论(0)    收藏  举报