jeudi 21 décembre 2017

Returning Value from 0/1 Grid

Hey there! I am new to Python and programming in general. I have found a way of printing a grid of random 0 and 1. I need to save these grids and to count the amount of 0's in them. This is what I have so far: (Im using Python 2.7)

import random
foo = ['0', '0', '0', '1', '1']
x = random.choice(foo)
A = [[random.choice(foo), random.choice(foo), random.choice(foo), random.choice(foo)],
[random.choice(foo), random.choice(foo), random.choice(foo), random.choice(foo)],
        [random.choice(foo), random.choice(foo), random.choice(foo), random.choice(foo)],
        [random.choice(foo), random.choice(foo), random.choice(foo), random.choice(foo)],
        [random.choice(foo), random.choice(foo), random.choice(foo), random.choice(foo)]]


print('\n'.join([''.join(['{:4}'.format(item) for item in row]) 
          for row in A]))




Aucun commentaire:

Enregistrer un commentaire