Python in 4 sittings: Sitting 2

Introduction to Python

Summary of the second class

20th June, 2021

© pi4py.netlify.app

feel free to contact us;

arabindo@protonmail.com

kaustavbasu97@gmail.com

Part A

Ternary Operator

At first we will revisit simple if-else statement and start optimizing it, which in turn lead us to Ternary Operator

RegEx is here with out much explanation. We will provide a better note later.

You can look into the official documentation: https://docs.python.org/3/library/re.html

Part B

Application of Dictionary

Design a Tic-toc-toe game

The idea is to have a function which will print the tic toc toe board using the dictionary values. The dictionary value will be updated based on user input.

On every iteration user will iput the the position of his turn, like 00, 01 and so on.

Position table(Alternatively, you can name them as 11,12,13,21,22,23,31,32,33...It's completely your choice):

col1 col2 col3
row1 00 01 02
row2 10 11 12
row3 20 21 22

We will print the board in the following way:

 | | 
-+-+-
 | | 
-+-+-
 | |

Counting character and words from a string

Before that, we will need some tool

Let's get back to the business

Now let's say we have the following string in our message variable

message="JupyterLab is a web-based interactive development environment for Jupyter notebooks, code, and data. JupyterLab is flexible: configure and arrange the user interface to support a wide range of workflows in data science, scientific computing, and machine learning. JupyterLab is extensible and modular: write plugins that add new components and integrate with existing ones."

We want to count the repeatation of the character in our string

Automate the typing!

That's it for today! Try to solve the problem sheet!

Cheers, Happy coding :)