Untitled 8
Untitled 8
# Easy way to to say "while this statement is true, then keep doing this thing"
# Below for example we are saying. As long as or "while" the smaller number is
# less than, or equal to the larger number (smaller <= larger), then the program
will take
# what the smaller number is at the moment and add it too the total (total = total
+ smaller).
# After this we will increment the smaller number by 1 (smaller = smaller +1) and
this
# prcess will only happen until the smaller number has been incremented enough
times until
print "END OF WHILE LOOP\nTOTAL AFTER WHILE LOOP: " + str(total) + "\n\n\n\n"
# For Loop Explanation: Here we set up a for loop. In simple terms a for loop is
saying
# an easier example is taking a basket of fruit, say that for every piece of fruit
in this
# basket you want to take one bite, the actual python version of this would be :
# below is where it's saying "for every fruit in the basket do this thing"
# And this is where you state the action you want to take for every fruit
# For this loop, the "fruit" is the "incrementer" variable and the "basket"
# will be a list of numbers starting from the smaller and going up to what
# the larger number is, we create this "basket" by using range(smaller, larger +1)
# which creates a list of numbers between the smaller and larger numbers (not
inclusively)
# Now we state that for every fruit (incrementer) in the basket (list of numbers)
# we are going to take that fruit (incrementer) and add it to the total