Good evening (* ´ω `)
There are things like that, human beings. In such a case, you can visit, take a walk, After that, I will organize what I understand.
Do you know what you've done so far ?? (laughs)
Even if you try to write to your computer Only the negative image of a deadlock comes up, so For the time being, I tried handwriting. I will also implement it on the stack.
I tried it without seeing anything, At first I'm at a loss because my hands don't move (laughs) But only the trunk part is fine Write it, import it to your PC, and try it. What's missing, how can I sublimate the code? Think about it and change it.
After boiling down to some extent, I tried to sort out if there was any problem. ** Rough specifications ** ** 1. User interface has 3 choices (push / pop / end) ** ** 2. Include exception handling ** ** 3. The number of data that can be buffered is 5 * The number is mood **
stack.py
class stack_sys:
def __init__(self,size=5):
buff =[]
self.buff = buff
self.size = size
def push(self,InD):
if len(self.buff) >= self.size:
print("full")
print(self.buff)
else:
self.buff.append(InD)
def pop(self):
if len(self.buff) <= 0:
print("empty")
else:
return self.buff.pop() # pop(0)Change to queue
stack = stack_sys()
if __name__ == "__main__":
while True:
sel_mode = int(input("1.push,2.pop,3.break"))
if sel_mode == 1:
try:
Din = int(input(""))
stack.push(Din)
except:
pass
elif sel_mode == 2:
try:
Dout = stack.pop()
print(Dout)
except:
pass
else:
break
If you get stuck in the program What do you guys do? Please try it as if you were deceived, it will be refreshing (≧ ▽ ≦)
Today, by chance, I came across If you want to learn the power of programming. I was greatly saved by the idea of continuing and gradually deepening. Run existing code like me and understand only the surface It seems that it is not a mistake to write an article, ** I understand that it doesn't make any sense to end up with that alone. ** **
Drop your image from scratch into the code I would like to build up a solid understanding of myself. We will update the shortages in the past articles in the future.
Please continue to give us your support. m (_ _) m
Recommended Posts