On Monday we covered 'basic python' and made loops. loops.py i=1 while i<5: print i i=i+1 The end result is a loop in the terminal that counts from 1 to 4. The next program we created was a back loop: backloop.py i=10 while 0<i<11: print i i=i-1 This program counts back from 10 to 1. "Everythird" was to see if one can print out a list, but only every 3rd number. This one counts from 1-100...in threes...starting from 1 and 4. everythird.py i=1 while i<101: print i i=i+3 The next program was titles "Milestone 1" and if you can do this you can do a lot in programming (supposedly). :P milestone1.py i=0 total=0 while i<6: total=total+(i) print i i=i+1 print total Now, this is a little tricky. I'm going to break down exactly what is going on. i=0, in the address "i" there is currently nothing allocated there. total=0, in the address "total" there is nothing currently allocated while i<6:, AS LONG AS the variable in the address 'i' is under 6... total=total+(i), the variable in the address "total" is ADDING ITSELF PLUS THE CURRENT VALUE OF "i" print i, print the current value of "i" i=i+1, the variable in the address "i" is ADDING ITSELF PLUS 1 print total, prints the current value of "total" The tricky part usually comes from not knowing how to |
