[PYTHON] I got stuck so I reviewed it

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. IMG_0036.jpg ** 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

I got stuck so I reviewed it
I researched Docker, so I will summarize it
I studied about Linux, so I summarized it.
I got an SSL related error with pip install, so I solved it
I got stuck installing Anaconda 4.3.0 which became Python 3.6
I referred to it when I got stuck in the django geodjango tutorial (editing)
I thought "What is Linux?", So I looked it up.
When I tried to introduce python3 to atom, I got stuck
[Streamlit] I installed it
I like Python's comprehension, so I compared it with map
I got a sqlite3.OperationalError
I got InsecurePlatformWarning in python, so I installed requests [security]
AWS Lambda now supports Python so I tried it
I got stuck doing Django1.4, so I wrote a "memo" about absolute path and relative path.
I got an error when pip install pandas on Mac, so I dealt with it
When I made CaboCha usable with python3, I got stuck (Windows 10)
Mezzanine introduction memo that I got stuck in the flow
What I got stuck around GUI in WSL python environment
PyTorch's book was difficult to understand, so I supplemented it
I got an SSL Error when I installed Anaconda in a new environment, so I solved it (Windows10, Anaconda3-2019.10)
5 reasons I got into Python
W3C Validators didn't work with Sublime Text3 so I made it work
[Super basics of Python] I learned the basics of the basics, so I summarized it briefly.
I made a segment tree with python, so I will introduce it
I got stuck trying to install various things with Mac El captain pip, so make a note