Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import random
- def get_int(msg, min, default):
- while True:
- try:
- line = input(msg)
- if not line and default is not None:
- print("*default:",default)
- return default
- i = int(line)
- if i < min:
- print("*must be >=", min)
- else:
- return i
- except ValueError as err:
- print(err)
- rows = get_int("rows: ", 1, 20)
- columns = get_int("columns: ", 1, 10)
- min = get_int("min: ", -1000, 0)
- default = 1000
- if min > default:
- default = min * 2
- max = get_int("max: ", min, default)
- row = 0
- while row < rows:
- line = ""
- column = 0
- while column < columns:
- rand = random.randint(min,max)
- line += str(rand)
- cnt = 0
- while True:
- if 10 - len(str(rand)) - cnt > 0:
- line += " "
- cnt += 1
- else:
- break
- column += 1
- print(line)
- row += 1
Add Comment
Please, Sign In to add comment