Try running the basic information Python sample problem only in the browser

Introduction

In the Fundamental Information Technology Engineer Examination (hereinafter referred to as the FE Examination), the programming questions changed from COBOL to Python. Python will be given from the fall exam of 2020 (the original plan was from the spring exam of 2020, but the spring exam was canceled due to the influence of Corona). One of the features of Python is that it is easy for beginners to learn. However, even if it is easy to learn as a language, it will be difficult for beginners to prepare an "environment to run and try Python" by themselves. Therefore, in this article, I will explain the preparation of the Python environment for those who "want to try Python for the FE exam but do not know how to make it work". In addition, let's actually move the Python sample problem published by IPA (FE test executing agency).

Audience of this article

――First time in programming. ――I want to take the FE exam. ――I want to learn Python. But I don't know how to run a Python program. ――I can understand the keywords of the morning questions of the FE exam somehow, or I can understand them if I look them up.

Things to prepare

--Google account (OK if you have a gmail account) --Environment where browsers such as Chrome can be used (Mac or Windows is OK)

Python runtime environment

In order to operate a programming language, an editor or compiler interpreter is often installed on a personal computer. Moreover, you have to overcome quite high hurdles such as installing the necessary libraries and getting used to the operation of the development environment (IDE). Thankfully, Google Sama provides an environment where you can run Python with just a web browser, and you can use it for free. Originally it seems to be an environment for practicing machine learning (although it is quite full-scale), but you can also move the sample questions of the FE exam. This environment is called Colaboratory. In this article, we will use Colaboratory to run the sample program.

Access Colaboratory

Let's access it now. Go to https://colab.research.google.com/ in your browser (Chrome recommended). If you are not logged in to your Google account, please log in from the login icon in the upper right. image.png

When you log in, the notebook list screen appears. A notebook is like a folder for organizing related files. If you are studying for the FE exam, it is a good idea to make one question correspond to one notebook. Click Create New Notebook to create a notebook for the sample questions. image.png

The code input screen will appear immediately. Rename your notebook to make it easier to read later when you open it. Click the default name, Untitled0.ipynb, and change it to sample.ipynb.

image.png image.png

After renaming the file, enter the sample program in the code entry area (the area surrounded by the line, called the cell). image.png

Of course, manual input is the most studying. However, for those who want to have fun, I will post a sample program. Please copy and paste.

sample.py


#The copyright belongs to IPA.
import math
import matplotlib.pyplot as plt

def parse(s):
  return [(x[0],int(x[1:])) for x in s.split(';')]

class Marker:
  def __init__(self):
    self.x, self.y, self.angle = 0, 0, 0
    plt.xlim(-320, 320)
    plt.ylim(-240, 240)

  def forward(self, val):
    rad = math.radians(self.angle)
    dx = val * math.cos(rad)
    dy = val * math.sin(rad)
    x1, y1, x2, y2 = self.x, self.y, self.x + dx, self.y + dy
    plt.plot([x1, x2], [y1, y2], color='black', linewidth=2)
    self.x, self.y = x2, y2
  def turn(self, val):
    self.angle = (self.angle + val) % 360
  def show(self):
    plt.show()
def draw(s):
  insts = parse(s)
  marker = Marker()
  stack = []
  opno = 0
  while opno < len(insts):
    print(stack)
    code, val = insts[opno]
    if code == 'F':
      marker.forward( val )
    elif code == 'T':
      marker.turn( val )
    elif code == 'R':
      stack.append({'opno': opno, 'rest': val })
    elif code == 'E':
      if stack[-1]['rest'] > 1 :
        opno = stack[-1]['opno']
        stack[-1]['rest'] -= 1
      else:
        stack.pop()
    opno += 1
  marker.show()

After entering the code, let's execute it. Click the run icon on the left. The first run will take some time. image.png

... Nothing comes out. That should be the case, in this sample program, only the definitions of functions and classes are written, and there is no equivalent to the main routine. Now let's call this function or class. Click "+ Code" at the top of the page. image.png

Then, another cell will appear below the cell where you entered the sample program. image.png

In this cell, execute the draw function explained in the sample problem as "Interpret and execute each instruction in the instruction sequence given as an argument and display the drawing result". For the argument, use the option (R5; F100; T72; E0) that is the answer to the question sentence blank b, and enter "draw ('R5; F100; T72; E0')". After entering, press the execute icon on the left. image.png

If you enter the sample code and the entered character string matches, the pentagon should be displayed as shown below. image.png

When you're done, save your notebook. You can open the saved notebook next time. Click "Save" from "File" at the top of the screen. Once you have saved it, you can close your browser. image.png

Thank you for your hard work.

Recommended Posts

Try running the basic information Python sample problem only in the browser
Basic information Write the 2018 fall algorithm problem in Python
Python in the browser: Brython's recommendation
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Display Python 3 in the browser with MAMP
The basics of running NoxPlayer in Python
Solve the maximum subarray problem in Python
Try hitting the YouTube API in Python
Try to calculate a statistical problem in Python
Try to solve the Python class inheritance problem
[Cloudian # 7] Try deleting the bucket in Python (boto3)
Try using the BitFlyer Ligntning API in Python
Until you run the changefinder sample in python
[Mac] Run the RealSense D415 sample in Python
This is the only basic review of Python ~ 1 ~
The 18th offline real-time writing problem in Python
This is the only basic review of Python ~ 2 ~
This is the only basic review of Python ~ 3 ~
Try implementing the Monte Carlo method in Python
The 19th offline real-time writing problem in Python
Try using the DropBox Core API in Python
Location information data display in Python --Try plotting with the map display library (folium)-
Basic sorting in Python
[Python] Try to read the cool answer to the FizzBuzz problem
Try to solve the internship assignment problem with Python
Try gRPC in Python
Try 9 slices in Python
Try running python in a Django environment created with pipenv
Try scraping the data of COVID-19 in Tokyo with Python
Solve the Japanese problem when using the CSV module in Python.
Try running a function written in Python using Fn Project
Prepare Backtrader CSV data and try running the sample script
Refactoring Learned in Python (Basic)
Download the file in Python
Find the difference in Python
Try running Python with Try Jupyter
Try implementing Yubaba in Python 3
Plot geographic information in Python
Wrapper running Hadoop in Python
[Python] Solving the import problem due to the difference in entry points
[Cloudian # 6] Try deleting the object stored in the bucket with Python (boto3)
Try transcribing the probability mass function of the binomial distribution in Python
The 15th offline real-time how to write reference problem in Python
Quickly install OpenCV 2.4 (+ python) on OS X and try the sample
[Cloudian # 2] Try to display the object storage bucket in Python (boto3)
The 14th offline real-time how to write reference problem in python
Solve the subset sum problem with a full search in Python
The 18th offline real-time how to write reference problem in Python
Try using FireBase Cloud Firestore in Python for the time being
Getting the arXiv API in Python
[Note] Project Euler in Python (Problem 1-22)
Save the binary file in Python
AtCoder: Python: Daddy the sample test.
Scraping with Selenium in Python (Basic)
Hit the Sesami API in Python
Try the Python LINE Pay SDK
Get the desktop path in Python
Try implementing extension method in python
ABC166 in Python A ~ C problem
Try using LevelDB in Python (plyvel)