#!/usr/bin/bash from random import random # You have a bookstore, with a finite capacity. def generate_store(capacity=100): return generate_books(number=capacity) # In each set of books, some are worth something and others aren't. def generate_books(quality=0.25, number=20): return [random() < quality for _ in range(number)] # We need to display what the stuff looks like, right? def print_books(store): print("".join("*" if book else "." for book in sorted(store))) # Here's your store. capacity = 100 store = generate_store(capacity) # How are we looking? print_books(store) # On your first day, all the good books get bought. store = [book for book in store if not book] # Oh, we need to replace them now. replacements = capacity - len(store) store.extend(generate_books(number=replacements)) # How are we looking? print_books(store) # Great, all the good books get bought. store = [book for book in store if not book] # Replacing them again... replacements = capacity - len(store) store.extend(generate_books(number=replacements)) # How are we looking now? print_books(store)