Studying Python with freeCodeCamp part1

The freeCodeCamp curriculum has been added!

The following curriculum has been added to freeCodeCamp. (See this article)

  1. Scientific Computing with Python
  2. Data Analysis with Python
  3. Information Security
  4. Machine Learning with Python

It's a big deal, so I decided to take this opportunity to study. In this article, I will introduce what I did with * Scientific Computing with Python *.

I tried Scientific Computing with Python

This field was broadly divided into the following two.

In * Python for Everbody *, I was able to learn basic syntax, networks, databases, etc. from the part of what is Python by using video + selection questions. All the videos are in English, so I managed to decipher them using subtitles and translations.

In * Scientific Computing with Python Projects *, problems are actually raised and you can learn by writing and submitting code. Even if you don't have a local execution environment, you can rest assured that an environment called repel.it that runs on the browser is provided. (I copied and wrote the source locally) In addition, a test code is also available and can be submitted if all tests are passed.

In the next few articles, I will introduce the problems raised by * Scientific Computing with Python Projects * and my personal points.

Question 1: Arithmetic Formatter

The final thing I want is the ʻarithmetic_arranger` method, and the behavior is as follows

arithmeric_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])

Output:

   32      3801      45      123
+ 698    -    2    + 43    +  49
-----    ------    ----    -----

In addition, a bool type value can be specified in the second argument, and when True, the calculation result must also be output.

Implementation policy

Upper parts ( 32 3801 45 123), Medium parts (+ 698 --2 + 43 + 49), Divide into lower parts (----- ------ ---- -----) and connect them with \ n at the end.

I don't want to post my implementation because I want everyone to try it ...

Personal point: Right-justified, center-justified, left-justified string

This problem requires the top, middle, and bottom parts to be aligned to the right, as shown below.

○○○32
+○698
-----

○:Blank

So the string method rjust () was used. (Center justified: center (), Left justified: ljust ()) Also, if you want to right-justify the numerical value, use it after converting it to a character string once with str ().

I right-justified as follows.

"""
    top_num=32, mid_num=698 
    top_num_len=2, mid_num_len=3
    op='+' or '-'
"""

row_len = max(top_num_len, mid_num_len) + 2 # +And one space
top = top_num.rjust(row_len)
mid = op + mid_num.rjust(row_len - 1)

Finally

As you can see, when you solve a problem, you often find things that you don't use often (in this case, the method of character alignment), so it's a lot of fun.

The next issue is * Time Calculator *.

Recommended Posts

Studying Python with freeCodeCamp part1
Studying Python with freeCodeCamp part2
Image processing with Python (Part 2)
Bordering images with python Part 1
Scraping with Selenium + Python Part 1
Image processing with Python (Part 1)
Solving Sudoku with Python (Part 2)
Image processing with Python (Part 3)
Scraping with Selenium + Python Part 2
Studying python
Playing handwritten numbers with python Part 1
[Automation with python! ] Part 1: Setting file
Studying Python Part.1 Creating an environment
Automate simple tasks with Python Part0
[Automation with python! ] Part 2: File operation
Excel aggregation with Python pandas Part 1
QGIS + Python Part 2
FizzBuzz with Python3
Scraping with Python
Statistics with python
Play handwritten numbers with python Part 2 (identify)
FM modulation and demodulation with Python Part 3
Process Pubmed .xml data with python [Part 2]
Scraping with Python
Python with Go
QGIS + Python Part 1
Automate simple tasks with Python Part1 Scraping
Twilio with Python
Integrate with Python
Play with 2016-Python
100 Language Processing Knock with Python (Chapter 2, Part 2)
AES256 with python
Tested with Python
Working with Azure CosmosDB from Python Part.2
[Python] Start studying
python starts with ()
Excel aggregation with Python pandas Part 2 Variadic
100 Language Processing Knock with Python (Chapter 2, Part 1)
with syntax (Python)
FM modulation and demodulation with Python Part 2
Python: Scraping Part 1
Bingo with python
Zundokokiyoshi with python
[Part1] Scraping with Python → Organize to csv!
Excel with Python
Python3 Beginning Part 1
Microcomputer with Python
Python: Scraping Part 2
Cast with python
Machine learning starting with Python Personal memorandum Part2
Create test data like that with Python (Part 1)
Machine learning starting with Python Personal memorandum Part1
How to measure execution time with Python Part 1
Create fractal shapes with python part1 (Sierpinski Gasket)
[Cloud102] # 1 Get Started with Python (Part 1 Python First Steps)
How to measure execution time with Python Part 2
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Python with eclipse + PyDev.
Socket communication with Python