Gen-AI Developer Classroom notes 17/Sep/2025

python contd


def is_prime(number:int) -> bool:
    """Checks if the number is prime or not

    Args:
        number (int): number

    Returns:
        bool: True if prime False otherwise
    """
    if number < 2:
        return False
    result = True
    index = 2
    while index <= number // 2:
        if number % index == 0:
            result = False
            break
        index += 1
    return result

number = 13195
index = number // 2
result = 0
while index >= 2:
    if number % index == 0: # factor
        if is_prime(index):
            result = index
            break
    index -= 1
print(result)

Functions in python

  • A function is reusable code block
  • syntax
def <name>(<args>):
    ...
    ...

docstring

  • Docstrings can document modules, classes and functions
  • Using docstring we can generate the documentation.
  • For docstrings we would be using google style guide
  • Prompt
As a python expert, Give me some examples for function doc strings 
  • Install an extension autoDocstring from vscode

Casing

  • CAMEL Casing
index
myIndex
  • Pascal Casing
Index
MyIndex
  • Snake Casing: In python to define variables and functions snake casing is recommended
index
my_index
  • Lets write a python function to calulate factorial of a number
5! = 5 * 4 * 3 * 2 * 1

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

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

Continue reading