PythonPlacement Classroomnotes 14/Feb/2022

Pythonic Thinking

Visual Studio Code

  • Install Visual Studio Code from Here Refer Here
  • Now install Python Extension
    Preview
    Preview
  • Enter Ctrl+Shift+P and Type Terminal: Focus Terminal
    Preview
    Preview
  • Now lets create a new virtual environment python -m venv venv in the terminal
    Preview
  • Now lets activate virtual environment in Powershell
    Preview
  • Lets activate virtual environment is visual studio code (Enter Ctrl+Shift+P => Python: Select Interpreter)
    Preview
  • Now Select the interpreter in ./venv/Scripts/python.exe

Debugging the Python Code using Visual Studio Code

  • Lets try to write a simple python function which adds two numbers and returns the result
  • Google has a pythons style guide Refer Here
  • For Docstring Refer Here
def add(number_1, number_2):
    """Adds two numbers

    Args:
      number_1: This is the first number
      number_2: This is the second number

    Returns:
      sum of two arguments passed 

    """
    return number_1 + number_2

if __name__ == "__main__":
    num_1 = 10
    num_2 = 20
    result = add(num_1, num_2)
    # Lets change the output to something like 10 + 20 => 30
    print(f"{num_1} + {num_2} => {result} ")

HackerRank Python Problems

if __name__ == '__main__':
    n = int(input())
    if not 1 <= n <= 150:
        exit(1)
    for index in range(1, n+1):
        print(index, end='')

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner