Matt Cline's CS Portfolio

Navigation

Contact Me


Email:  mattjcline@gmail.com
Cell #:  (312) 545-1156
AIM:  Clinerbiner9er
Twitter

Digg



HOME‎ > ‎

Code Samples

backloop.py

i=10
while i>0:
  i=i-1
  print i


This program, if run in terminal, will countdown from the number 10.  It lists in reverse order because of the third line: "i=i-1".
To make is run through from least to greatest all one has to do is change the '-' to a '+'. 

total.py
 
i=0
t=0
while i<5:
  i=i+1
  t=t+i
  print t


This program as two variables.  This is the complex thing I have written so far (lulz).  It adds 1+2+3+4+5 in order to get 15.  Since i starts at 0, the first time line 4 is processed, i is equivalent to 1.  The program continues this opperation until i is 5.  The variable 't' is in place to keep track of all the times the variable 'i' is added up.  So through the course of 'i' being added 5 times, 't' reflects that total sum is 15.