Recent site activity

Python Work

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)

Attachments (10)

  • backloop.py - on May 4, 2009 10:23 PM by talvarado@usfca.edu (version 1)
    1k Download
  • blueThirdColumn..py - on May 4, 2009 11:05 PM by talvarado@usfca.edu (version 1)
    1k Download
  • compoundInterest.py - on May 4, 2009 10:07 PM by talvarado@usfca.edu (version 1)
    1k Download
  • conditionalinterest.py - on May 4, 2009 10:51 PM by talvarado@usfca.edu (version 1)
    1k Download
  • conditionalinterest_2.py - on May 4, 2009 10:51 PM by talvarado@usfca.edu (version 1)
    1k Download
  • everythird.py - on May 4, 2009 10:23 PM by talvarado@usfca.edu (version 1)
    1k Download
  • firstfive.py - on May 4, 2009 10:23 PM by talvarado@usfca.edu (version 1)
    1k Download
  • greenFourthRows.py - on May 4, 2009 11:05 PM by talvarado@usfca.edu (version 1)
    1k Download
  • interestRate.py - on May 4, 2009 10:07 PM by talvarado@usfca.edu (version 1)
    1k Download
  • redBorder.py - on May 4, 2009 11:05 PM by talvarado@usfca.edu (version 1)
    1k Download