When printing the rows of the array/canvas you might add \n to the end of each row and print the canvas all at once rather than a print statement for each row.
Vincent Davis 720-301-3003 On Sat, Jan 4, 2014 at 3:10 PM, Vincent Davis <vinc...@vincentdavis.net>wrote: > You might think about using an array to represent the canvas. Starting > with it filled with "" and then for each point change it to "X". > The print the rows of the array. > > You can make the array/canvas arbitrarily large and then plot multiple > different paths onto the same array. > > > Vincent Davis > 720-301-3003 > > > On Sat, Jan 4, 2014 at 9:15 AM, Jason Friedman <jsf80...@gmail.com> wrote: > >> I am teaching Python to a class of six-graders as part of an after-school >> enrichment. These are average students. We wrote a non-GUI "rocket >> lander" program: you have a rocket some distance above the ground, a >> limited amount of fuel and a limited burn rate, and the goal is to have the >> rocket touch the ground below some threshold velocity. >> >> I thought it would be neat, after a game completes, to print a graph >> showing the descent. >> >> Given these measurements: >> measurement_dict = { # time, height >> 0: 10, >> 1: 9, >> 2: 9, >> 3: 8, >> 4: 8, >> 5: 7, >> 6: 6, >> 7: 4, >> 8: 5, >> 9: 3, >> 10: 2, >> 11: 1, >> 12: 0, >> } >> >> The easiest solution is to have the Y axis be time and the X axis >> distance from the ground, and the code would be: >> >> for t, y in measurement_dict.items(): >> print("X" * y) >> >> That output is not especially intuitive, though. A better visual would >> be an X axis of time and Y axis of distance: >> >> max_height = max(measurement_dict.values()) >> max_time = max(measurement_dict.keys()) >> for height in range(max_height, 0, -1): >> row = list(" " * max_time) >> for t, y in measurement_dict.items(): >> if y >= height: >> row[t] = 'X' >> print("".join(row)) >> >> My concern is whether the average 11-year-old will be able to follow such >> logic. Is there a better approach? >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> >> >
-- https://mail.python.org/mailman/listinfo/python-list