I am working with this code so I have my main code here:
from draw_image import Images
start = Images()
start.display_image()
start.delete_line()
start.display_image()
and this is my draw_image code:
class Images:
def image(jumper_image):
"""This function is to create the list"""
jumper_image = []
def display_image(jumper_image):
"""This is how the user will see the image correctly through the loop"""
jumper_image = [
" ___ ",
" /___\ ",
" \ / ",
" \ / ",
" o ",
" /|\ ",
" / \ ",
" ",
"^^^^^^^^^^^"
]
for image in jumper_image:
print(image)
return jumper_image
def delete_line(jumper_image):
""" This function is supposed to delete the first line of the jumper_image"""
jumper_image.pop(0)
It seems that the delete_line function is not recognizing the list, do you guys have any idea why this is happening? or what would be a solution for this problem?
CodePudding user response:
I would recommend using a python constructor to initialize jumper_image:
class Images:
def __init__(self):
self.jumper_image = [
" ___ ",
" /___\ ",
" \ / ",
" \ / ",
" o ",
" /|\ ",
" / \ ",
" ",
"^^^^^^^^^^^"
]
def display_image(self):
"""This is how the user will see the image correctly through the loop"""
for image in self.jumper_image:
print(image)
def delete_line(self):
""" This function is supposed to delete the first line of the jumper_image"""
self.jumper_image.pop(0)
start = Images()
start.display_image()
start.delete_line()
print('After deleting first value in list\n')
start.display_image()
___
/___\
\ /
\ /
o
/|\
/ \
^^^^^^^^^^^
After deleting first value in list
/___\
\ /
\ /
o
/|\
/ \
^^^^^^^^^^^
