Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
binary 2d chart
#1
My assignment is to create a class called "Squares", whose __init__(self, n) creates a table of 2**n by 2**n filled with zeros, and a function "turn(str)" which takes a string of a numbers. The digits of the number are by order the position of which quarter of the square gets turned from zero to one and vice versa, assuming 1 is upper left, 2 is upper right, 3 is lower left and 4 is lower right. So if my input is d=Suares(2), it would initialize an 4 by 4 table. d.turn('1') would turn all the numbers in the upper left quarter to their binary opposites. So d would look like this
[1, 1, 0, 0]
[1, 1, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
However starting from a blank table of zeros d.turn('12') would turn numbers in the second quarter of the first quarter. So d would look like this
[0, 1, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
[0, 0, 0, 0]
I was thinking of splitting the string into a list and then slowly working into it using some elifs but don't know where to start. Any help is appreciated.
Reply
#2
(Nov-20-2019, 10:18 PM)feyristan Wrote: but don't know where to start
We get that a lot, but what we really want to see is an honest attempt, always.

For example, I don't know what you mean by this
(Nov-20-2019, 10:18 PM)feyristan Wrote: splitting the string into a list and then slowly working into it using some elifs
And honestly, I don't understand your assignment; you say you need turn() "[take] a string of numbers" but that's ambiguous, do are the numbers whitespace separated? You then later say "number" (no S) and it sounds like a number as a string, which begs the question - why?

If you have a verbatim you can share, that would probably help us to help you. Otherwise, some examples would go a long way.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020