登录后查看本帖详细内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
5.31: year=eval(input('enter the year of you want :')) what_day=eval(input('enter the first day of one year: ')) def calender(month,year,what_day,days): print(format(str(month)+str(year),'^50s')) print('-'*50) print('Sun\tMon\tTue\tWed\tThu\tFri\tSat\t') print(' \t'*what_day,end='') count=0 for i in range(1,days+1): print(format(i,'^3d'),end=''+'\t') count+=1 if (what_day+count) % 7==0: print() print() calender('January',year,what_day,31) FebFirstDay=(what_day+31 % 7) % 7 if year % 400 ==0 or (year % 4 == 0 and year % 100 != 0): days=29 else: days=28 calender('February',year,FebFirstDay,days) if year % 400 ==0 or (year % 4 == 0 and year % 100 != 0): MarFirstDay=(FebFirstDay+29 % 7) % 7 else: MarFirstDay=(FebFirstDay+28 % 7) % 7 calender('March',year,MarFirstDay,31) AprFirstDay=(MarFirstDay+31 % 7) % 7 calender('April',year,AprFirstDay,30) MayFirstDay=(AprFirstDay+30 % 7) % 7 calender('May',year,MayFirstDay,31) JunFirstDay=(MayFirstDay+31 % 7) % 7 calender('June',year,JunFirstDay,30) JulFirstDay=(JunFirstDay+30 % 7) % 7 calender('July',year,JulFirstDay,31) AugFirstDay=(JulFirstDay+31 % 7) % 7 calender('August',year,AugFirstDay,31) SepFirstDay=(AugFirstDay+31 % 7) % 7 calender('September',year,SepFirstDay,30) OctFirstDay=(SepFirstDay+30 % 7) % 7 calender('October',year,OctFirstDay,31) NovFirstDay=(OctFirstDay+31 % 7) % 7 calender('November',year,NovFirstDay,30) DecFirstDay=(NovFirstDay+30 % 7) % 7 calender('December',year,DecFirstDay,31) 5.32: amount=eval(input('enter an amount:')) year_rate=eval(input('enter the year_rate:')) month=eval(input('enter the month:')) total=0 for i in range(1,month+1): total=(100+total)*(1+year_rate/1200) print(format(total,'.3f')) 5.33: amount=eval(input('enter an amount:')) year_rate=eval(input('enter the year_rate:')) month=eval(input('enter the month:')) total=amount*(1+year_rate/1200) print('Month\tCD Value') print(format('1','5s')+'\t'+format(total,'.2f')) for i in range(2,month+1): total=total*(1+year_rate/1200) print(format(i,'<5d')+'\t'+format(total,'.2f')) 5.34: import random a=random.randint(0,9) b=random.randint(0,9) while a==b: b=random.randint(0,9) else: if a == 0: print(str(a)+str(b)) else: number=a*10+b print(number) 5.35: number=10000 for j in range(2,number+1): sum=0 for i in range(1,j): if j % i == 0: sum+=i if sum == j: print(j) 5.36: import random count1=0 count2=0 while count1 < 2 and count2 < 2: guess=eval(input('enter scissor(0),rock(1),paper(2):')) computer=random.randint(0,2) if guess == computer: print('computer is'+str(computer)+',it is draw!') elif (guess==0 and computer==1) or (guess==1 and computer==2) or (guess==2 and computer==0): print('computer is'+str(computer)+',computer win!') count1+=1 elif (guess==0 and computer==2) or (guess==1 and computer==0) or (guess==2 and computer==1): print('computer is'+str(computer)+',you win!') count2+=1 print('computer win '+str(count1)+' times,you win '+str(count2)+' times,game over!') 5.37: import math sum=0 for i in range(1,625): sum=sum+1/(math.sqrt(i)+math.sqrt(i+1)) print(sum) 5.38: import time number=eval(input('enter the number of seconds:')) while number > 0: print(str(number)+'seconds remaining') time.sleep(1) number-=1 print('stopped') 5.39: salary=5000 fees=0 number=0.01 while (salary+fees)<30000: if 0.01 <= number <= 5000: fees=number * 8 /100 elif 5000 < number <= 10000: fees=5000*8/100+(number-5000)*10/100 elif 10000 < number : fees=5000*8/100+5000*10/100+(number-10000)*12/100 number+=0.01 print(number,salary+fees) 5.40: import random count1=0 count2=0 for i in range(1000000): number=random.randint(0,1) if number==0: count1+=1 else: count2+=1 print('正面出现了'+str(count1)+'次,反面出现了'+str(count2)+'次')
|