tynation.com           Monday, April 25, 2011

IT104

So today in Intro to Programming we had a test. I was the first one done. They also handed out awards for honors and perfect attendance. I got one for highest honors and perfect attendance. Anyway here's the code that I wrote for the test today:

#Program Start
secA = 15          #Variables Start
secB = 12          #Tyler Cooper
secC = 9          #4-25-11
seatedA = 0
seatedB = 0
seatedC = 0
profitsA = 0
profitsB = 0
profitsC = 0
totalProfits = 0
profitGoal = 3000          #Variables End
print "How many seats were sold in section A?"     #Input Start
seatedA = input()
print "How many seats were sold in section B?"
seatedB = input()
print "How many seats were sold in section C?"
seatedC = input()          #Input End
profitsA = secA * seatedA     #Processing Start
profitsB = secB * seatedB
profitsC = secC * seatedC
totalProfits = profitsA + profitsB + profitsC     #Processing End
print "Todays sales profits were \$", totalProfits     #Output Start
if (totalProfits >= profitGoal):
print "Sales profit exceeds goal of \$3000"
else:
print "Sales profit below goal of \$3000"          #Output End
#Program End

Notes

Loops: 2 Types

Determinant

Loop where you know the exact number of repitions.

Indeterminate

Loop where you dont know how many times code will loop

Determinate loop: usually called for loop

for x in range(1, 10):

numbers in parenthensis are called arguments

x controls how many times the code loops

this for loop will start at 1 and go to 9

x = 0
for x in range(1,10):
print x

this will print 1 through 10

counter = 0
endcount = 0
print "Enter a number for code to repeat:"
endcount = input() + 1
for counter in range (1, endcount):
print counter

When dealing with user input for loops add 1 to their input so they get the actual amount they need

counter = 0
endcount = 0
average = 0
endcount = input()
for counter in range (1, endcount + 1):

you can use this code to find the average of all the values put in witout a lot of variables

counter = 0
for counter in range (0, 26, 5,):
print counter

will print 0, 5, 10, 15, 20, 25

counter = 0
for counter in range (50, 4, -5):
print counter

will print 50, 45, 40, 35, 30, 25, 20, 15, 10, 5
Lab Code:

bugTotal = 0               #Tyler Cooper
counter = 0               #Variables
day = 0
for counter in range (1, 8):
day = day + 1
print "How many bugs did you collect on day", day
bugTotal = bugTotal + input()          #Bug total is cumulative
print "over", day, "days you collected", bugTotal, "bugs"

Homework Code:

calories = 3.9          #Tyler Cooper
counter = 10          #Calories Burned!
calBurn = 0%nbsp;          #Variables End
for counter in range (10, 31, 5):%nbsp;%nbsp;%nbsp;%nbsp;%nbsp;%nbsp;%nbsp;%nbsp;#for loop
calBurn = counter * calories
print "You burn", calBurn, "calories in", counter, "minutes"

Other News

I was contacted by a new potential employer today. I'm thinking this may be the one to hire me. The company is Rooftop Digital Imaging.