Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9108305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:46:39+00:00 2026-06-17T02:46:39+00:00

I’m writing a program that the user must input a binary matrix. how can

  • 0

I’m writing a program that the user must input a binary matrix. how can i do that.
What is the best way to say the user how to input that matrix?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:46:41+00:00Added an answer on June 17, 2026 at 2:46 am

    There are many different possibilities. For example:

    First, you could use a spreadsheet-like GUI (or similar curses UI), console-style text input, or all kinds of other things.

    Assuming you’ve decided on going with console input, the most obvious solution is probably space-separated columns, newline-separated rows. But that may not be the best solution for your use case.

    If you users might want to copy and paste the output of one run into the input of the next, you probably want to either allow or require the brackets and commas as you’re going to print them out. Or, if they might copy from a CSV file, allow or require commas. And so on.

    If the matrices have to be square, you don’t need the newlines. On the other hand, having them makes the input look nicer, and allows you to give much better error handling (“row 3 has 8 values instead of 7” vs. “you entered 50 values instead of 49”).

    Since the values are binary, you don’t need the spaces either. This has similar tradeoffs.

    You could also use two characters closer together on the keyboard than 1 and 0, or more visually distinct (e.g., X and .), or more relevant to your problem space.

    And so on. The point is, there is no one “best way”; there are dozens of tradeoffs to be made, and maybe even innovative design decisions that will lead to even more tradeoffs.

    Once you pick one, they’re almost all easy to implement. For example, let’s do space-separated columns, newline separated rows, with a blank line meaning the end:

     print("Please enter your matrix as 1s and 0s, with spaces between the columns.")
     print("Use one row per line, and a blank row when you're done.")
     matrix = []
     while True:
         line = input()
         if not line: break
         values = line.split()
         row = [int(value) for value in values]
         matrix.append(row)
    

    You can obviously merge some of those lines together, or turn the whole thing into a list comprehension or a generator, but I left it like this so you can add whatever error handling you find appropriate. (You may notice there’s no error handling at all—if you enter the wrong number of columns on some line you’ll get a jagged matrix; if you accidentally type q instead of 1 it’ll raise an exception; etc.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.