The list of problems for this week's exam is at: http://www.cs.indiana.edu/classes/a201-dger/sum2009/weekThree.txt Today we want to discuss problems 3, 6, 5. Tomorrow we want to work on 1, 2, 4 -- to be ready for Friday. I'll post the code we develop in class right here. Here's how I would start on the Vending Machine: +----------------------------------------------------------- | print "Welcome to the Vending Machine!" | | line = raw_input("enter> ") +----------------------------------------------------------- Next we can establish a communication loop: +----------------------------------------------------------- | print "Welcome to the Vending Machine!" | | line = raw_input("enter> ") | | while line != "done": | line = raw_input("enter> ") | | print "Thanks for using this program." +----------------------------------------------------------- Now it looks like we could get to the coins one by one: +----------------------------------------------------------- | print "Welcome to the Vending Machine!" | | line = raw_input("enter> ") | | while line != "done": | coins = line.split() | for coin in coins: | print coin | line = raw_input("enter> ") | | print "Thanks for using this program." +----------------------------------------------------------- If we can establish a balance and update it every time we look at a coin we're basically done: +----------------------------------------------------------- | print "Welcome to the Vending Machine!" | | line = raw_input("enter> ") | | balance = 0 | | while line != "done": | coins = line.split() | for coin in coins: | if coin == "dime": | balance += 10 | elif coin == "quarter": | balance += 25 | elif coin == "nickel": | balance += 5 | else: | print "I don't understand", coin | print "$" + str(balance / 100.0) | line = raw_input("enter> ") | | print "Thanks for using this program." +----------------------------------------------------------- And that's basically it.