Python Classroom Notes – 03/Mar/2020

Debugging: Closer look again

  • Purpose: Take control of code execution to identify issues/understand someone else’s code.

Debugging Terms

  • Breakpoint: Point/Line of code from which you want to take control of code execution
  • Step Over: Execute the current line and stop execution at next
  • Continue: Continue Execution by taking over
  • local variables: values of variables will be shown

Visual Studio Code

  • Step1: Download visual studio code from here
  • Step 2: Install Python Extension Preview
  • Step 3: Setting up Debugging using visual studio code Preview
  • Step 4: Set the breakpoint (use shortcut of F9) Preview
  • Step 5: Variables Preview

Start Debugging the Program Below (Project Euler 3)

# This program accepts input from user and displays 
# whether the input is prime or not
number = int(input("Enter any number of your choice "))
for factor in range(number,2,-1):
    if number%factor == 0:
        # seems like a factor
        # now let me check if it is prime or not
        is_prime = True
        for index in range(2,factor):
            if factor%index == 0:
                is_prime = False
                break
        if is_prime:
            print (f"largest prime factor of {number} is {factor}")
            exit(0)

Multi line strings

  • """ are used to have a string which is multi lined
  • sample code with all the possible string notations in python
name = "Lamborghini"
category = 'car'
message = """ wonderful car to have
needs hell lot of money
so start earning
"""
singline_message = "wonderful car to have \nneeds hell lot of money\nso start earning"
print(f"name is {name}. Its a {category}. {message}")
print('#########################################################')
print(f"name is {name}. Its a {category}. {singline_message}")

Exploring strings

  • Open Python shell and ignore any thing in between __ (double underscores)
>>>help(str)

# Continue Enter Key press till special methods are not shown


  • Exercise: Try to use atleast 5 methods of string
  • Exercise: Try to see if one string in contained in other string
x = 'ing'
y = 'swing'
z = 'great'
x <something>  y => Return any thing which describes presence
x <something> y  => Return any thing which describes absence

Leave a Comment

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

About continuous learner

devops & cloud enthusiastic learner