Let's write a program that keeps state. Aaron says: a) guess the number program b) input is a number c) state is: the secret number (may change after win/lose) wins, losses (these are numbers) attempts failed in a current game Let's write a program that keeps track of your account balance. Write a program: #!/usr/bin/perl use CGI; $car = new CGI; print "Content-type: text/html\n\n"; # print $car->header, $car->start_html; print qq{
Your current balance is: ...

Enter amount to deposit/withdraw:

Press to move on.

}; print ""; Call this program type 34 and push Proceed, the url changes: http://silo.cs.indiana.edu:8346/cgi-bin/0915/two?amount=34 So this program prints a form that collects data for it. We change the program as follows: #!/usr/bin/perl use CGI; $car = new CGI; $amount = $car->param('amount'); $balance = $car->param('balance') + $amount; print "Content-type: text/html\n\n"; # print $car->header, $car->start_html; print qq{
You sent me: $amount

Your current balance is: $balance

Enter amount to deposit/withdraw:

Press to move on.

}; print ""; This works but is kind of ugly. But it works. So we can clean it later. Please try to solve the challenge stated in lab for Thursday. I write it here again from the Prereqs for this week: Challenge One. Implement a script that * first asks for the name, * then collects it and uses it to * ask for the age, * then collects the age and * finally prints the final report. Here's a model for it (not much help, I am sure). -bash-3.2$ ./three Welcome to the program. What's your name: Larry Bird Well Larry Bird how old are you now: 17 Well Larry Bird next year you will be 18 years old -bash-3.2$ cat three #!/usr/bin/python print "Welcome to the program." name = raw_input("What's your name: ") age = raw_input("Well " + name + " how old are you now: ") print "Well", name, "next year you will be", int(age) + 1, "years old" -bash-3.2$ So we need to do this, but on the web. Write a web script with this behaviour.