[Python] How to make percent chance that there will be a * in a 2D array decrease

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    My result

    I need to make the number of stars decrease with each line, but I have no idea how.

    I need help!!!!

    import random
    import numpy as np
    import sys

    size = int(sys.argv[1])
    mat = np.full((size, size), '\x1b[35m.')

    def random_int():
    random_num = random.randint(0, len(mat) - 1)
    return random_num

    def print_array():
    for y in range(0, len(mat)):
    for x in range(0, len(mat[y])):
    j = random_int()
    mat[y][j] = '\x1b[37m*'
    print(mat[y][x], end="")
    print()

    print_array()

    Continue reading...

Compartilhe esta Página