Yeah, there are few ones to make it more pythonic, I'd use a dictionary packing all the data, ie:
import random
if __name__ == "__main__":
random.seed(1)
week_data = {
1: (0, 32),
2: (0, 8),
3: (7, 15),
4: (14, 22),
5: (21, 29)
}
for i in range(10):
whichweek = random.randint(1, 5)
dayf, dayt = week_data[whichweek]
print whichweek, dayf, dayt
If you want to handle errors, you can use something like this:
import random
if __name__ == "__main__":
random.seed(1)
week_data = {
1: (0, 32),
2: (0, 8),
3: (7, 15),
4: (14, 22),
5: (21, 29)
}
for i in range(10):
whichweek = random.randint(1, 10)
res = week_data.get(whichweek, None)
if res is None:
print("Error: {0} is not in week_data".format(whichweek))
else:
dayf, dayt = res
print whichweek, dayf, dayt
Finally, if you want to avoid that conditional check, return always values like this:
import random
if __name__ == "__main__":
random.seed(1)
week_data = {
1: (0, 32),
2: (0, 8),
3: (7, 15),
4: (14, 22),
5: (21, 29)
}
for i in range(10):
whichweek = random.randint(1, 10)
dayf, dayt = week_data.get(whichweek, (None, None))
print whichweek, dayf, dayt