Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def plot(data):
- """Plot data down the page, larger values plot to the right."""
- for value in data:
- print(" "*value + "*")
- print() # a blank line to end
- data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- # plot the unchanged data
- print(data)
- plot(data)
- # change data to value mod 5
- mod_data = [value%5 for value in data]
- print(mod_data)
- plot(mod_data)
- # 'reflect' any value greater than limit of 5
- limit = 5
- mod_data = []
- for value in data:
- if value > limit:
- value = 2*limit - value
- mod_data.append(value)
- # a list comprehension is probably too complicated
- #mod_data = [value if value <= limit else 2*limit - value for value in data]
- print(mod_data)
- plot(mod_data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement