fork download
  1. def draw_graph(y_min, y_max, x_min, x_max, input_values):
  2. x_offset = len(str(x_max)) # For when x has more than 1 digit
  3. for i in range(x_max, x_min - 1, -1):
  4. print(" " * (x_offset - len(str(i))) + str(i), end="")
  5. prev_chars = x_offset
  6. for value in input_values:
  7. a, b, f = value
  8. if f >= i:
  9. n_spaces = x_offset + sum([
  10. len(str(j)) for j in range(y_min, b, 10)
  11. ]) + ((a-y_min) // 10) - prev_chars
  12. print(" " * n_spaces + "*", end="")
  13. prev_chars += n_spaces + 1
  14. print()
  15. print(" " * x_offset, end="")
  16. for i in range(y_min, y_max + 1, 10):
  17. print(str(i), end=" ")
  18. print()
  19.  
  20.  
  21. # Read values
  22. y_min, y_max, x_min, x_max = [int(i) for i in input().split(' ')]
  23.  
  24. n = int(input())
  25.  
  26. input_values = []
  27. for _ in range(n):
  28. x, y, f = [int(i) for i in input().split(' ')]
  29. input_values.append((x, y, f))
  30.  
  31. # Call the function
  32. draw_graph(y_min, y_max, x_min, x_max, input_values)
Success #stdin #stdout 0.01s 9992KB
stdin
0 50 1 10
5
0 10 1
10 20 3
20 30 6
30 40 4
40 50 2
stdout
10
 9
 8
 7
 6       *
 5       *
 4       *  *
 3    *  *  *
 2    *  *  *  *
 1 *  *  *  *  *
  0 10 20 30 40 50