1. Tyler thinks about a problem (Yahtzee, etc.) 2. Na Li stores info in a file (Python) f = open("log.txt", "w") while True: line = raw_input("Enter>") if line == "bye": break f.write(line + "\n") f.close() f = open("log.txt", "r") lines = f.readlines() for line in lines: print line, f.close() These are actually two programs. What if the file needs to be opened/closed inside the while? 3. Aaron: game of craps, extension #!/usr/bin/python import cgi, random print "Content-type: text/html\n\n" data = cgi.FieldStorage() if data.has_key("numbers"): a = data["numbers"].value a = a.split(",") else: a = [] if len(a) > 0: random.shuffle(a) else: a = [3, 2, 4, 4, 1, 5, 2, 3] for i in range(len(a)): a[i] = str(a[i]) a = ",".join(a) print """
""" % (a, a) I implemented this as silo.cs.indiana.edu:8346/cgi-bin/aaron Program needs to be tested from command line too: ./aaron Q: Can you split an array of numbers? A: You can split a string -- is that what you want to do to the array too? Q: Ah, no. No problem. But, what does this do: a = "1,2,3,4,5" b = a.split(",") What is b? A: An array of strings. Q: OK, so that's what I really wanted. Can you split a string into an array of ints? A: Not in one step, but you can get there in two-three steps. Q: So now can you join an array of ints? A: Who splits and joins? Q: Strings. A: So a string like "2,3,4,5,6" can split. It splits into an array of ints. Q: Okay, who joins then? A: Strings, you said. Q: So to join I choose the glue and the glue joins: " ".join(a)? A: Yes, and if a is not an array of strings it doesn't work. Q: I see... 5. Beibit: step one, working on dark hearts. 6. Na Li web script prototype phase one: -bash-3.2$ pwd /u/dgerman/apache/cgi-bin -bash-3.2$ cat nali #!/usr/bin/python print "Content-type: text/html\n\n" import cgi data = cgi.FieldStorage() comment = "" if data.has_key("comment"): comment = data["comment"].value f = open("/u/dgerman/apache/htdocs/log.txt", "w") f.write(comment) f.close() print """ """ -bash-3.2$