习题5_2.py
#!/usr/bin/python def MyMultiple(x, y): return x * y for i in range(1, 10): for j in range(1, i + 1): print ‘%d * %d = %2d‘ % (j, i, MyMultiple(i, j)), if j == i: print
习题5_3.py
#!/usr/bin/env python InputScore = int(raw_input(‘Input a integer: ‘)) if InputScore >= 90: print ‘Your score is A (90~100)‘ elif InputScore >= 80: print ‘Your score is B (80~89)‘ elif InputScore >= 70: print ‘Your score is C (70~79)‘ elif InputScore >= 60: print ‘Your score is D (60~69)‘ else: print ‘Your score is F (<60)‘
习题5_4.py
#!/usr/bin/env python StartYear = int(raw_input(‘Input Start Year: ‘)) StopYear = int(raw_input(‘Input Stop Year: ‘)) if StartYear > StopYear: StartYear, StopYear = StopYear, StartYear for EachYear in range(StartYear, StopYear + 1): if (EachYear % 4 == 0 and EachYear % 100 != 0) or \ (EachYear % 4 == 0 and EachYear % 100 == 0): print ‘%d is RunNian‘ % EachYear else: print ‘%d is PingNian‘ % EachYear
时间: 2024-11-18 14:41:50