Guest User

Untitled

a guest
Jul 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import random
  4.  
  5. def get_int(msg, min, default):
  6. while True:
  7. try:
  8. line = input(msg)
  9.  
  10. if not line and default is not None:
  11. print("*default:",default)
  12. return default
  13.  
  14. i = int(line)
  15.  
  16. if i < min:
  17. print("*must be >=", min)
  18. else:
  19. return i
  20. except ValueError as err:
  21. print(err)
  22.  
  23. rows = get_int("rows: ", 1, 20)
  24. columns = get_int("columns: ", 1, 10)
  25. min = get_int("min: ", -1000, 0)
  26.  
  27. default = 1000
  28. if min > default:
  29. default = min * 2
  30.  
  31. max = get_int("max: ", min, default)
  32.  
  33. row = 0
  34. while row < rows:
  35. line = ""
  36. column = 0
  37. while column < columns:
  38. rand = random.randint(min,max)
  39. line += str(rand)
  40. cnt = 0
  41. while True:
  42. if 10 - len(str(rand)) - cnt > 0:
  43. line += " "
  44. cnt += 1
  45. else:
  46. break
  47. column += 1
  48. print(line)
  49. row += 1
Add Comment
Please, Sign In to add comment