Compounded Interest: principal=3000 interestRate=.1 oneYearInterest=interestRate*principal print'interest is:',oneYearInterest principal= input('enter principal:') interestRate=input ('enter rate:') oneYearInterest= interestRate*principal print"interest is:", oneYearInterest oneYearPrincipal = principal + oneYearInterest print"One Year Principal:",oneYearPrincipal principal= input('enter principal:') interestRate=input ('enter rate:') oneYearInterest= interestRate*principal print"interest is:", oneYearInterest oneYearPrincipal = principal + oneYearInterest print"One Year Principal:",oneYearPrincipal twoYearInterest=interestRate*oneYearPrincipal twoYearPrincipal = oneYearPrincipal+ twoYearInterest print"Two Year Principal:",twoYearPrincipal threeYearInterest=interestRate*twoYearPrincipal threeYearPrincipal= twoYearPrincipal + threeYearInterest print"Three Year Principal:",threeYearPrincipal Loop programs: Backloop- i=10 while i>0: print i i=i-1 Every third- i=1 while i<101: print i i=i+3 First Five- number=1 while number<15: number=number+2+3+4+5 print number Conditional Statements: conditional interest- principal = input ('enter amount') interestrate=.1 if principal>=10000: interestrate=.2 if principal>=50000: interestrate=.25 print interestrate principal=2 interest after years- p=input('please enter the principal') n=input('please enter the number of years') i=1 while i<=n: if p>50000 and i<4: rate=.25 elif p>=10000 and i<4: rate=.2 elif p<10000 and i<4: rate=.1 else: rate=.3 p=p*rate+p i=i+1 print p Images, Pixels and nested loops redborder: filename=pickAFile() pic=makePicture(filename) show(pic) w=getWidth(pic) col=1 while col<w: row=1 while row<100: pixel=getPixel(pic,col,row) setColor(pixel,red) row=row+1 col=col+1 repaint(pic) blue third columns: filename=pickAFile() pic=makePicture(filename) show(pic) w=getWidth(pic) h=getHeight(pic) col=1 while col<w: row=1 while row<h: pixel=getPixel(pic,col,row) setColor(pixel,blue) row=row+1 col=col+3 repaint(pic) green fourth row: filename=pickAFile() pic=makePicture(filename) show(pic) w=getWidth(pic) h=getHeight(pic) col=1 while col<w: row=1 while row<h: pixel=getPixel(pic,col,row) setColor(pixel,green) row=row+4 col=col+1 repaint(pic) |