Display matrix of 0s and 1s
Write a function that displays an n-by-n matrix using the following header:
def printMatrix(n):
Each element is 0
or 1
, which is generated randomly. Write a test program that prompts the user to enter n and displays an n
-by-n
matrix. Here is a sample run:
Enter n: 3 010 000 111
Here is my idea:
from __future__ import print_function from random import randint, choice import random n = input ("Enter an interger number:") k = randint(0, 1) for i in range (1, n+1): for j in range (1, n+1): print (format((i*j)/(i*j)*k, "3d") , end = '') print ()
Related Posts:
- What does random.sample() method in python do?
- Random string generation with upper case letters and digits
- How can I randomly select an item from a list?
- How to get a random number between a float range?
- Python: Array v. List
- Generate random sentences in python
- Shuffle an array with python, randomize array item order with python
- use np.random.multinomial() in python
- Generate random colors (RGB)
- Get a random sample with replacement
- Simple way to create matrix of random numbers
- Generate a random letter in Python
- Random word generator- Python
- Shuffle an array with python, randomize array item order with python
- When should I use uuid.uuid1() vs. uuid.uuid4() in python?
- ImportError: No module named tensorflow
- Best way to convert string to bytes in Python 3?
- How do you change the size of figures drawn with Matplotlib?
- PermissionError: [Errno 13] Permission denied
- How to find if directory exists in Python
- What is setup.py?
- JSONDecodeError: Expecting value: line 1 column 1 (char 0)
- Cannot find module cv2 when using OpenCV
- What is the purpose and use of **kwargs? [duplicate]
- Invalid character in identifier
- if else in a list comprehension
- What does “\r” do in the following script?
- Convert list to tuple in Python
- Python: TypeError: object of type ‘NoneType’ has no len()
- anaconda – path environment variable in windows
- Pandas: ValueError: cannot convert float NaN to integer
- How to find all occurrences of an element in a list
- pygame.error: video system not initialized
- TypeError: ‘numpy.float64’ object is not callable
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- ‘str’ object has no attribute ‘decode’. Python 3 error?
- How to find all the indexes of a recurring item in a list?
- Is there a way to delete created variables, functions, etc from the memory of the interpreter?
- Code for Greatest Common Divisor in Python
- ‘DataFrame’ object has no attribute ‘sort’
- How to check Django version
- How to change the font size on a matplotlib plot
- How can I create a dropdown menu from a List in Tkinter?
- How to find all occurrences of a substring?
- Django upgrading to 1.9 error “AppRegistryNotReady: Apps aren’t loaded yet.”
- Pygame Drawing a Rectangle
- Purpose of `numpy.log1p( )`?
- How do I change the figure size for a seaborn plot?
- How to use pyinstaller?
- Contains of HashSet
in Python - How to take column-slices of dataframe in pandas
- Python: Get the first character of the first string in a list?
- How to convert string to binary?
- Python error load JSON code of google API
- How do I find the duplicates in a list and create another list with them?
- ‘Pip’ is Not Recognized as an Internal or External Command windows 10 CMD
- Failed to load the native TensorFlow runtime – TensorFlow 2.1
- Using headers with the Python requests library’s get method
- ImportError: libSM.so.6: cannot open shared object file: No such file or directory
- explain arguments meaning in res = cv2.bitwise_and(img,img,mask = mask)
- How to normalize a 2-dimensional numpy array in python less verbose?
- Remove xticks in a matplotlib plot?
- “for line in…” results in UnicodeDecodeError: ‘utf-8’ codec can’t decode byte
- TypeError: string argument without an encoding
- How to truncate float values?
- How do I write a “tab” in Python?
- TypeError: ‘builtin_function_or_method’ object has no attribute ‘__getitem__’
- Why does PyQt crashes without information? (exit code 0xC0000409)
- How can I check if character in a string is a letter? (Python)
- raise LinAlgError(“SVD did not converge”) LinAlgError: SVD did not converge in matplotlib pca determination
- How to multiply all integers inside list
- How can I get the named parameters from a URL using Flask?
- Python Error – TypeError: input expected at most 1 arguments, got 3 [duplicate]
- A general tree implementation?
- TypeError: expected string or buffer
- How to convert a file into a dictionary?
- RuntimeWarning: overflow encountered in ubyte_scalars
- Converting a RGB color tuple to a six digit code
- mean, nanmean and warning: Mean of empty slice
- SystemError: new style getargs format but argument is not a tuple?
- Python Set Comprehension
- Split string using a newline delimiter with Python
- Why am I getting ImportError: No module named pip ‘ right after installing pip?
- No module named urllib3
- How to convert index of a pandas dataframe into a column
- Python requests SSL error – certificate verify failed
- How to know/change current directory in Python shell?
- Trying to run Flask app gives “Address already in use”
- How is Python’s List Implemented?
- ImportError: No module named IPython
- How to find length of digits in an integer?
- What exactly do “u” and “r” string flags do, and what are raw string literals?
- “E: Unable to locate package python3-pip”
- Eclipse, PyDev “Project interpreter not specified”
- How to exit an if clause
- Python a &= b meaning?
- ValueError: total size of new array must be unchanged
- No handlers could be found for logger
- TypeError: ‘NoneType’ object has no attribute ‘__getitem__’
- File “/usr/bin/pip”, line 9, in
from pip import main ImportError: cannot import name main