I want to save the trouble of inputting when debugging Paiza's skill check example in a local environment such as Jupyter [Python]

Greeting

This article is the first post. I would like to write down what I was interested in, so I would appreciate your favor.

Introduction What is paiza skill check?

The paiza skill check is a programming skill test that can be taken at paiza, a site operated by paiza Co., Ltd., which aims to develop IT human resources and support job hunting. Users are ranked according to the difficulty of the problems they have cleared in this skill check, and may be scouted by the company that saw the code.

Purpose of this article

** Example of questions Escape from the troublesome copy and paste work when debugging ** Most programming test questions, including paiza's skill checks, have input and output examples as examples, so you'll start with that example. In the case of paiza, you can try it online from the bottom of the problem screen and check the operation, but as the difficulty increases and the code becomes longer, you will want to debug it in small pieces with Jupyter Notebook etc. ( At least I will). In that case, you will have to copy and paste the input example, but it is ** troublesome ** to copy each line line by line, but ** I also want to write it in the same form as when I submitted it ** .. So I want to do something, let's do something. So I managed to do it.

What happened

To put it simply, I overloaded the ** ʻinput ()` function, or overwrote it **.

The following image is an input example of Introduction to paiza learning skill check. this image.png The goal is to create a function that can be used simply by substituting it like this. image.png ・ ・ ・

paiza_test.py


def preinput(input_text):
    out=input_text.split("\n")
    for i in out:
        yield i

def input(reset=False):
    global input_text,inp
    if reset:del inp,input_text,repeat;return
    try:return inp.__next__()
    except:
        if repeat:inp=preinput(input_text)
        return inp.__next__()

def def_input(s,isRepeat=False):
    global input_text,inp,repeat
    input_text=s
    repeat=isRepeat
    inp=preinput(input_text)

** Done ** (Miscellaneous). Place this as a py file in the directory to be debugged and import it for use.

debug.ipynb


from paiza_test import*

As before, prepare a variable to which the input example is assigned and throw it into the def_input () function, and you are ready **.

debug.ipynb


input_text="""6
apple
book
information
note
pen
pineapple"""

def_input(input_text)

After that, you can write the code you want to debug in ** as-is **.

debug.ipynb


n=int(input())
for i in range(n):
    print(input())

output


apple
book
information
note
pen
pineapple

By default, when the input reaches the end, an error will be thrown the next time it is called, but if the argument ʻisRepeat is specified as Truewhen callingdef_input ()`, it will be output repeatedly from the beginning.

python


def_input(input_text,isRepeat=True)
n=int(input())
for i in range(3*n):
    print(input())

output


apple
book
information
note
pen
pineapple
6
apple
book
information
note
pen
pineapple
6
apple
book
information
note

Also, if you call the argument reset with True, it will be reset to the state before calling def_input () (there is no return value).

def_input(input_text)
input(reset=True)

input()  #------> error

3/16 postscript Fixed the setting timing of ʻisRepeat when calling def_input () `.

Summary

I hope this article has reached people with the same dissatisfaction and helped me ... Besides paiza, I think it can be used for debugging other programming contests such as AtCoder. If you have a better way or improvement, please leave a comment.

Recommended Posts

I want to save the trouble of inputting when debugging Paiza's skill check example in a local environment such as Jupyter [Python]
LINEbot development, I want to check the operation in the local environment
I made a program to check the size of a file in Python
I want to use Python in the environment of pyenv + pipenv on Windows 10
How to check the memory size of a variable in Python
How to check the memory size of a dictionary in Python
When generating a large number of graphs with matplotlib, I do not want to display the graph on the screen (jupyter environment)
I want to build a Python environment
If you want a singleton in python, think of the module as a singleton
(Python Selenium) I want to check the settings of the download destination of WebDriver
How to install python package in local environment as a general user
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I want to sort a list in the order of other lists
I want to color a part of an Excel string in Python
Python: I want to measure the processing time of a function neatly
I want to load the pytest fixture as a library somewhere else (pytest may not exist in the environment)
[Python] I want to know the variables in the function when an error occurs!
I created a script to check if English is entered in the specified position of the JSON file in Python.
I want to create a window in Python
I want to set a life cycle in the task definition of ECS
I want to see a list of WebDAV files in the Requests module
Python program is slow! I want to speed up! In such a case ...
I want to display the progress in Python!
[Example of Python improvement] I learned the basics of Python on a free site in 2 weeks.
How to check in Python if one of the elements of a list is in another list
I want to be notified of the connection environment when the Raspberry Pi connects to the network
I want to write in Python! (1) Code format check
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I want to write in Python! (2) Let's write a test
I want to randomly sample a file in Python
I want to work with a robot in python.
I want to write in Python! (3) Utilize the mock
I want to use the R dataset in python
I want to do something in Python when I finish
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
I want to see the graph in 3D! I can make such a dream come true.
I tried to create a Python script to get the value of a cell in Microsoft Excel
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
The story I was addicted to when I specified nil as a function argument in Go
When I got a list of study sessions in Python, I found something I wanted to make
Check the operation of Python for .NET in each environment
I want to start a jupyter environment with one command
I want to start a lot of processes from python
I made a function to check the model of DCGAN
How to develop in a virtual environment of Python [Memo]
I want to use a virtual environment with jupyter notebook!
I want to know the features of Python and pip
I want to make input () a nice complement in python
How to write when you want to put a number after the group number to be replaced with a regular expression in re.sub of Python
I want to improve efficiency with Python even in the experimental system (5) I want to send a notification at the end of the experiment with the slack API
Run the output code on the local web server as "A, pretending to be B" in python
When you want to use multiple versions of the same Python library (virtual environment using venv)
A story that didn't work when I tried to log in with the Python requests module
I want to clear up the question of the "__init__" method and the "self" argument of a Python class.
How to determine the existence of a selenium element in Python
Save the result of the life game as a gif with python
[Linux] I want to know the date when the user logged in
[Python] PCA scratch in the example of "Introduction to multivariate analysis"
I want to output the beginning of the next month with Python