Python Classroom notes 13/Dec/2024

Programming

Project Euler 3

  • Problem statement
  • largest prime factor
  • Break this problem into finding factors in the reverse order
  • Solution
number = 20
index = number - 1
until index > 2
    if number % index == 0
        factor = index
        start = 2
        is_prime = true
        until start < factor
            if factor % start == 0:
                is_prime = false
                break (come out of until)
            start = start + 1
        end until
        if is_prime == true:
            say index is largest prime factor
            exit
    end if
    index = index - 1
end


Project Euler 5

max_number = 5
current = max_number
until true
    index = 2
    is_factor_of_all = true
    until index <= max_number
        if current % index != 0
            is_factor_of_all = false
            break (come out of until)
        end if
        index = index + 1
    end until
    if is_factor_of_all == true
        say current is the number divisible by all
        exit
    end if
    current = current + max_number
end until

System Setup

  • Sofwares Required
    • Git
    • Python
    • Visual Studio Code
  • Windows Users: Watch classroom video
  • Mac Users: Install homebrew and execute the following commands
brew install git
brew install python@3.13
brew install --cask visual-studio-code

Configuring Visual Studio Code for Python Development

  • Watch classroom video for steps
  • Install python extension for visual studio code

Debugging

  • Breakpoint: This is the line where code stops executing and gives you control
  • Step over: Execute the current line
  • Continue: Execute the code till the next break point or code finishing execution
  • Debugging in visual studio for individual files (Watch classroom recording)
  • Exercise: Debug the following code
max_number = 4
current = max_number
while True:
    index = 2
    is_factor_of_all = True
    while index <= max_number:
        if current % index != 0:
            is_factor_of_all = False
            break
        index = index + 1
    if is_factor_of_all == True:
        print(f"{current} is the lcm")
        break
    current = current + max_number
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

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

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%