Sunday, December 16, 2012

How to Find the Best Deal on Tuition

I'm attending school this fall. Finally! I am using my own money to pay for it. So, looking at this page, I wanted to find the best deal on credits:


http://opb.washington.edu/content/tuition-and-required-fees?year=2012-13&qtr=2&campus=0&category=1&res=1&submit=Submit

I wanted to know which amount of credits had the most value per dollar. I started writing a program. At first, I had the user enter the tuition rates manually. But, in testing, that became tedious. So I copied the data -- total amount in the rightmost column -- from the web page into a text file. Each amount was on a separate line, like so:

883
1289
1695
2101

Here is what I ended up writing today:

f = open('uw_tuition_rates.txt', 'r')
    
credits = 2

rates = []
for q in f.read().split():
    rates.append(int(q))
f.close()

x = rates[0]
y = rates[1]

while y != 0:
  print ("Tuition rate:", y)
  credits = credits + 1
  print ("Credits: ", credits)
  print ("difference: ", y - x)
  print ("ratio: ", y/credits, "dollars per credit")
  print ()
  x = y
  y = rates[credits-1]

If you run this code as a module, each amount is listed along with the number of credits it pays for. The difference between this amount and the previous amount is displayed. Finally, the desired information (the best deal!) is found on the "ratio" line. So as you can see, tuition from 10-18 credits is a flat rate of 4131. Therefore, 18 credits is the best value. But what wasn't apparent on the web page was that the amount of credits above 18 all have better value than credits below 15. In other words, even though 12 credits are the same price as 10 credits, 20 credits is cheaper than both.

Saturday, October 1, 2011

Test 0004: solving for a hypotenuse

#October 1, 2011
#Python 3.2 code by Carla Fuqua
#purpose: to allow a user to solve for a hypotenuse

#ask for values and assign to integers floats
w=float(input("Enter the width: "))
h=float(input("Enter the height: "))

#Pythagorean Theorem
hyp=(w*w+h*h)**(0.5)

#show hypotenuse
print('The hypotenuse is:',hyp)

#sweet!

Test 0003: receiving and processing user input

#October 1, 2011
#Python 3.2 code by Carla Fuqua
#purpose: to receive input and process it

#getting the input from the user
firstName=input('Enter your first name: ') #must add a space manually
lastName=input('Enter your last name: ')

#returning as output
print('''\nHello,''',firstName,lastName+"!") #commas turn into spaces, +'s do not
print(firstName+""", you have successfully completed this test.\
\nThank you for your participation.""")

Friday, September 30, 2011

Test 0002: finding a hypotenuse

#September 30, 2011
#Python 3.2 code by Carla Fuqua
#purpose: to find a hypotenuse

#again, input not yet learned

#assign arbitrary variables
width=3
length=4

#remember algebra class
#remember syntax for exponents
hyp=(width*width+length*length)**(1/2)

#print results
print (hyp)

#redefine variables as necessary :)

#...

#(basically just code for the Pythagorean Theorem)

Test 0001: reformatting data

#September 30, 2011

#Python 3.2 code by Carla Fuqua
#purpose: reformatting names "from a list"

#input from list not yet learned

#assign arbitrary variables
x="Carla"
y="Fuqua"

#print results; format Last, First
print (y+", "+x)

#continuing with the theory: to display results from an actual list, number each item in the list?
#print (number)
#then print (number+1) over and over
#loops? je ne sais pas!