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 8860351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:14:58+00:00 2026-06-14T15:14:58+00:00

The code below was provided to us and it basically prints that image which

  • 0

The code below was provided to us and it basically prints that image which is shown in the second function:

import sys



# CONSTANTS
MIN_ROW = 0
MAX_ROW = 9
MIN_COLUMN = 0
MAX_COLUMN = 9
WALL = "#"
BUILDING = "b"
BUSH = "u"
PLAYER = "@"
EMPTY = " "
STAIRS = "X"


def display (city):
   r = 0
   c = 0
   print("CITY LEVEL")
   for r in range (0, (MAX_ROW+1), 1):   #LOOPS1
      for c in range (0, (MAX_COLUMN+1), 1):
         sys.stdout.write(city[r][c])
      print()
   print()

def initialize ():
   r = 0
   c = 0
   city = []

   for r in range (0, (MAX_ROW+1), 1): #LOOP2
      city.append([])#appends an empty list to city
      for c in range (0, (MAX_COLUMN+1), 1):
       city[r].append(" ")
   #               0   1   2   3   4   5   6   7   8   9 
   city  [0] =   ["#","#","#","#","#","#","#","#","#","#"]
   city  [1] =   ["#","@"," "," "," "," "," "," ","u","#"]
   city  [2] =   ["#"," "," ","b","b"," "," "," ","X","#"]
   city  [3] =   ["#"," "," ","b","b"," "," "," "," ","#"]
   city  [4] =   ["#"," "," "," "," "," "," "," ","b","#"]
   city  [5] =   ["#","u"," ","u","u","u","u","u","u","#"]
   city  [6] =   ["#","b"," "," "," "," "," "," "," ","#"]
   city  [7] =   ["#"," "," "," "," ","b"," ","b"," ","#"]
   city  [8] =   ["#"," "," "," ","b"," "," "," "," ","#"]
   city  [9] =   ["#","#","#","#","#","#","#","#","#","#"]
   return city   


# MAIN
def main ():
     level = initialize ()
     display (level)





main ()

Now I am trying to reproduce this for a 1D picture but for some reason I am running into type errors for the sys.stdout.write() of the first function. It seems to be trying to print the entire list compared to just one character of it. Can anyone help me debug?. Also can someone please tell me what is going on in the loops in the above code labelled LOOPS1 AND LOOPS2

import sys


def display(track):
    c=0
    for c in range(0,20,1):
        sys.stdout.write(track[c])
    print()

def initialize():
    c=0
    track= []
    for c in range(0,20,1):
        track.append([])
        track[c].append(" ")
    track[0]= ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"]
    return track

level= initialize()
display(level)

If anything is unclear please let me know and I will fix it asap.

EDIT: CODE FOR MY PROGRAM:

import sys
import random


# CONSTANTS


PLAYER = "@"
EMPTY = " "


#Takes the information from the function initialize() and displays it. Outputs the fitness simulation.
def display (track):
    r = 0
    c = 0

    print("\nTRACK")
    for r in range (0, (4), 1):
        for c in range (0, (41), 1):
            sys.stdout.write(track[r][c])
        print()
    print()

def speedDisplay(speed):
    options=["(w)alk","(j)og","(r)un","(f)ast run"]
    for o in range(0,speed,1):
        print(options[o],"\n")




def inputs():#ioerror here?
    values= set("wWjJrRfFlLsSeE")
    while True:
        move=input("\nPlease select the speed you would like to travel at from the options listed:")
        for m in move:
            if m not in values:
                print("\nInadmissable entry, Please only use inputs valid in the options above.")
                break
        else:
            break
    if move=="w" or move=="W":
        usedEnergy=0#turn into random functions later
    elif move=="j" or move=="J":
        usedEnergy=1
    elif move=="r" or move=="R":
        usedEnergy=2
    elif move=="f" or move=="F":
        usedEnergy=5
    return usedEnergy

def remainingEnergy(energy,usedEnergy):
    energy= energy-usedEnergy
    print("\nRemaining Energy:",energy,"\n")
    return energy

def amountLeft(energy):
# enter ioexception error here somewhere?


    while True: 
        if energy <0 or energy >20:
            print("error")
        elif energy>=5:
            speed=4
        elif energy <5 and energy >=2:
            speed=3
        elif energy <2 and energy >=1:
            speed=2
        elif energy <1 and energy >=0:
            speed=1
        else:
            break

        return speed











# This function is used to initialize the game track that will later be displayed. 
def initialize ():
    r = 0
    c = 0
    track = []
    #Creates each row and column. A "for" loop initiates which creates and appends an empty list to the list "track". Then, taking the current row into consideration, the respective number of columns are created via the inner "for loop and a space is appended to the end of the current row. The loop re-initiates and the process is repeated for all 4 required rows. This results in 4 rows and 41 coloumns.
    for r in range (0, (4), 1):
    #appends an empty list to track
        track.append([])
        for c in range (0, (41), 1):
    #appends a space to the current row
            track[r].append(" ")
    # the actual rows and columns are created below.
    #               0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R   S   T   U   V   W   X   Y
    track  [0] =   [" ","0"," ","1"," ","2"," ","3"," ","4"," ","5"," ","6"," ","7"," ","8"," ","9"," ","A"," ","B"," ","C"," ","D"," ","E"," ","F"," ","G"," ","H"," ","I"," ","J"," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "]
    track  [1] =   [" ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," "]
    track  [2] =   ["|","@","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"," ","|"]
    track  [3] =   [" ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," ","-"," "]
    return track   






def move (sRow, sCol, dRow, dCol, track):
    EMPTY= " "
    PLAYER= "@"
    DIVIDER= "|"
    track[sRow][sCol] = EMPTY
    track[dRow][dCol] = PLAYER






# MAIN
def main ():
    track = initialize ()
    display (track)
    print("\n(w)alk\n\n(j)og\n\n(r)un\n\n(f)ast run")
    usedEnergy=inputs()
    energy=20
    energy=remainingEnergy(energy,usedEnergy)
    while energy<20:
        usedEnergy=inputs()
        speed= amountLeft(energy)
        speedDisplay(speed)
        energy=remainingEnergy(energy,usedEnergy)



main ()
  • 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-14T15:14:59+00:00Added an answer on June 14, 2026 at 3:14 pm

    Well, this works:

    import sys
    
    def display(track):
        c=0
        for c in range(0,20,1):
            sys.stdout.write(track[c])
        print()
    
    def initialize():
        c=0
        track = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t"]
        return track
    
    level= initialize()
    display(level)
    

    Your problem was you had a mismatch in how you’re handling track. In initialize you were creating it as a list of lists but in display you were accessing it as if it were just a list of characters. Making both a list of characters was simpler, making both a list of list of chars is more general (allows same function to be used for 1D and 2D case).

    What’s going on in the first loop?

    From display in your first code block:

    for r in range (0, (MAX_ROW+1), 1):   #LOOPS1
         for c in range (0, (MAX_COLUMN+1), 1):
             sys.stdout.write(city[r][c])
         print()
     print()
    

    R is a row index that varies from 0 to MAX_ROW, 0 – 9. C is a column index that varies from 0 to MAX_COLUMN, 0 – 9.

    sys.stdout.write(city[r][c]) writes out the current row and column of city (which has been set to a single character) without a newline.

    You’re code is probably Python 3 due to the print() statements. It would probably help if you mentioned or tagged that.

    I’m running Python 2.7 so I’ll use the old print syntax so I can test the the code I’m posting. You’ll probably have to revert it back (add parens).

    I would write this as:

    def display (city):
       print("CITY LEVEL")
       for row in city:
          for c in row:
             print c,
          print
       print
    

    In Python 2 a comma at the end of a print suppresses the newline.

    What’s going on in the second loop?

    From initialize in your first code block:

    for r in range (0, (MAX_ROW+1), 1):
    

    r will be 0 to MAX_ROW, 0-9

        city.append([])#appends an empty list to city
    

    city is a list. This appends an empty list to city.

        for c in range (0, (MAX_COLUMN+1), 1):
    

    c will b 0 to MAX_COLUMN, 0-9

            city[r].append(" ")
    

    Append a space character to the current row.

    I would write this as:

    def initialize():
       city = [
           # 0   1   2   3   4   5   6   7   8   9
           ["#","#","#","#","#","#","#","#","#","#"], # 0
           ["#","@"," "," "," "," "," "," ","u","#"], # 1
           ["#"," "," ","b","b"," "," "," ","X","#"], # 2
           ["#"," "," ","b","b"," "," "," "," ","#"], # 3
           ["#"," "," "," "," "," "," "," ","b","#"], # 4
           ["#","u"," ","u","u","u","u","u","u","#"], # 5
           ["#","b"," "," "," "," "," "," "," ","#"], # 6
           ["#"," "," "," "," ","b"," ","b"," ","#"], # 7
           ["#"," "," "," ","b"," "," "," "," ","#"], # 8
           ["#","#","#","#","#","#","#","#","#","#"], # 9
       ]
       return city
    

    about city.append([])

    In initialize there is a line (in the first for loop):

    city.append([])#appends an empty list to city
    

    Before the loop is entered city is:

    []
    

    Right after the first append city is:

    [[]]
    

    That is a list that contains one item, an empty list.

    If the line were:

    city.append(0)

    It would be:

    [0]
    

    Or:

    city.append("Jim")
    

    It would give you:

    ["Jim"]
    

    But we stick another list inside the list, creating a list of lists.

    I hope this helps.

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

Sidebar

Related Questions

I'm using the code provided below to display time and date. can anyone help
I am able to provide animation to an image button from below code. this.RegisterName(image1.Name,
The code below simply didn't work. document.getElementById('files').addEventListener('change', handleFileSelect, false); reported by firebug that this
In the code provided below, you will see a map made of various tiles.
I was using the below code provided by Google for Google Analytics. <script type=text/javascript>
I'm trying to find a subpalindrome in Java. But the below code doesn't provide
Code below is working well as long as I have class ClassSameAssembly in same
Code below is used to save PostgreSql database backup from browser in Apache Mono
This code below allows me to find the word error in all my files
The code below fails on the line: Class.forName(oracle.jdbc.driver.OracleDriver); with the error: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver The

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.