Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to create a 10x10 matrix with random numbers between 1 and 100 in Python

1 Answer

0 votes
import random
 
def CreateMatrix(rows, cols, start, end):
    # Create a rowsxcols matrix with random numbers between 1 and 100
    matrix = [[random.randint(start, end) for _ in range(cols)] for _ in range(rows)]
     
    return matrix
  
 
matrix = CreateMatrix(10, 10, 1, 100)
 
for row in matrix:
    for val in row:
        print('{:4}'.format(val), end="")
    print()


 

 
'''
run:
 
  31  65  53  53  38  62  43  66  84  26
  64  19  96   3  90  20  73  17  19  14
   8  76  74   9  68  34  34  52  58  40
  56  45  71  20  13  44  65  59   5  28
  88  59  76  13   8  18  14   3  50  67
  41  54  52  46   3  51  91  13  16  71
  64  55  26  66   5  14   1  72  34  89
  23  18  67  36  75  12  95  71  17   2
  71  69  13  33  60  92  84  25   9  37
   2  32  72  16  95  34  13  32  39  81
 
'''

 



answered Oct 30, 2023 by avibootz
edited Oct 30, 2023 by avibootz
...