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

  • Home
  • SEARCH
  • 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 228469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:41:05+00:00 2026-05-11T19:41:05+00:00

Can anyone tell me why num_chars and num_rows have to be the same? from

  • 0

Can anyone tell me why num_chars and num_rows have to be the same?

from ctypes import *

num_chars = 8
num_rows = 8
num_cols = 6

buffer = create_string_buffer (num_chars*num_rows*num_cols+num_chars)

for char in range(num_chars):
        for row in range(num_rows):
                for col in range(num_cols):
                        if char == num_chars-1 and col == num_cols-1:
                                buffer[row*num_rows*num_cols+char*num_cols+col+row] = '|'
                                buffer[row*num_rows*num_cols+char*num_cols+col+row+1] = '\n'
                        elif col == num_cols-1:
                                buffer[row*num_rows*num_cols+char*num_cols+col+row] = '|'
                        else:
                                buffer[row*num_rows*num_cols+char*num_cols+col+row] = ('.', '*')[char>row]

print buffer.value

The output

.....|*****|*****|*****|*****|*****|*****|*****|
.....|.....|*****|*****|*****|*****|*****|*****|
.....|.....|.....|*****|*****|*****|*****|*****|
.....|.....|.....|.....|*****|*****|*****|*****|
.....|.....|.....|.....|.....|*****|*****|*****|
.....|.....|.....|.....|.....|.....|*****|*****|
.....|.....|.....|.....|.....|.....|.....|*****|
.....|.....|.....|.....|.....|.....|.....|.....|

And now changing num_chars to 15.

.....|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
*****|*****|*****|*****|*****|*****|*****|*****|
.....|*****|*****|*****|*****|*****|*****|*****|
  • 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-05-11T19:41:05+00:00Added an answer on May 11, 2026 at 7:41 pm

    You said you are using ctypes because you want mutable char buffer for this. But you can get the output you want from list comprehension

    num_chars = 5
    num_rows = 8
    empty = ['.' * num_chars]
    full = ['*' * num_chars]
    print '\n'.join(
        '|'.join(empty * (i + 1) + (num_rows - i - 1) * full)
        for i in xrange(num_rows)
    )
    
    .....|*****|*****|*****|*****|*****|*****|*****
    .....|.....|*****|*****|*****|*****|*****|*****
    .....|.....|.....|*****|*****|*****|*****|*****
    .....|.....|.....|.....|*****|*****|*****|*****
    .....|.....|.....|.....|.....|*****|*****|*****
    .....|.....|.....|.....|.....|.....|*****|*****
    .....|.....|.....|.....|.....|.....|.....|*****
    .....|.....|.....|.....|.....|.....|.....|.....
    

    EDIT

    I’ll show you how you can use list comprehensions to draw whatever char bitmap you want to draw. The idea is simple. Build a boolean array with True in the places you want to print the character and False otherwise. And just use the ‘or’ trick to print the right character. This example will build a chess like board. You can use the same concept to draw any shape you want.

    rows = 5
    cols = 6
    char = '#'
    empty = '.'
    bitmap = [[ (i + j)%2 == 0 for i in xrange(cols)] for j in xrange(rows)]
    print '\n'.join(
        '|'.join(bitmap[j][i] * char or empty for i in xrange(cols))
        for j in xrange(rows)
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer For God's sake, don't. You really don't want to go… May 11, 2026 at 9:01 pm
  • Editorial Team
    Editorial Team added an answer Every nonfinal microsoft product is timebombed. May 11, 2026 at 9:01 pm
  • Editorial Team
    Editorial Team added an answer Actually, if you want the resulting URL to have an… May 11, 2026 at 9:01 pm

Related Questions

I was writing a database handler class in PHP using the mysqli class and
Can anyone tell me why the second cast fails to compile in Delphi 7?
Can anyone tell me why this isn't working? function changeBG(element_id){ document.getElementById(element_id).className= arrowActive; setTimeout(document.getElementById(+element_id+).className= 'arrow',
Can anyone tell me why the following code doesn't work the way I expect?
Is it me or are there no standard trim functions in the c or

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.