作业1:让用户输入数字,累加
作业2:存10000块钱,年利率是3.25,多少年之后,存款能翻倍
作业3:求用户输入数字的平均分
作业1:
#!/usr/bin/env python # -*- coding: utf-8 -*- x=0 while True: num=raw_input(‘Please input number [Q/q to exit] : ‘) if num == ‘q‘ or num == ‘Q‘: print ‘total num : %d‘ % x break elif num == ‘‘: continue else: x=x+int(num)
作业2:
#!/usr/bin/env python # -*- coding: utf-8 -*- x=0 s=0 while x < 10000: lixi = 10000 * 0.0325 x = x + lixi s+=1 print s
作业3:
#!/usr/bin/env python # -*- coding: utf-8 -*- x=0 count=0 while True: num=raw_input(‘Please input number [Q/q to exit] : ‘) if num == ‘q‘ or num == ‘Q‘: print ‘total num : %d‘ % x break elif num == ‘‘: continue else: x=x+int(num) count+=1 print "avg num : %s" % int(x/count)
时间: 2024-10-14 04:49:31