[关闭]
@3632qaz 2016-11-20T07:08:15.000000Z 字数 859 阅读 2207

python作业答案

uce


作业一第一题答案

  1. socre=int(raw_input())
  2. if socre>=90:
  3. print 'A'
  4. elif socre>60:
  5. print 'B'
  6. else:
  7. print'C'

作业一第二题答案

  1. for n in range(100,1000):
  2. i = n / 100
  3. j = n / 10 % 10
  4. k = n % 10
  5. if n == i ** 3 + j ** 3 + k ** 3:
  6. print n

作业一第三题答案

  1. word=raw_input('pleas input a word:\n')
  2. for i in word:
  3. print i+'\n'

作业二第一题答案

  1. def fib(n):
  2. if n==1 or n==2:
  3. return 1
  4. return fib(n-1)+fib(n-2)

作业二第二题答案

  1. s = raw_input('input a string:\n')
  2. letters = 0
  3. space = 0
  4. digit = 0
  5. others = 0
  6. for c in s:
  7. if c.isalpha():
  8. letters += 1
  9. elif c.isspace():
  10. space += 1
  11. elif c.isdigit():
  12. digit += 1
  13. else:
  14. others += 1
  15. print 'char = %d,space = %d,digit = %d,others = %d' % (letters,space,digit,others)

附加题答案

  1. year = int(raw_input('year:\n'))
  2. month = int(raw_input('month:\n'))
  3. day = int(raw_input('day:\n'))
  4. months = (0,31,59,90,120,151,181,212,243,273,304,334)
  5. if 0 < month <= 12:
  6. sum = months[month - 1]
  7. else:
  8. print 'data error'
  9. sum += day
  10. leap = 0
  11. if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
  12. leap = 1
  13. if (leap == 1) and (month > 2):
  14. sum += 1
  15. print 'it is the %dth day.' % sum
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注