ackermanmoriii / python-fundamentals

0 stars 0 forks source link

Rrr #33

Open ackermanmoriii opened 2 months ago

ackermanmoriii commented 2 months ago
import os
from docx import Document

def extract_student_name(text):
    """
    This function extracts the student name between "نام دانشجو:" and the next period ".".
    """
    start_marker = "نام دانشجو:"
    end_marker = "."

    try:
        start_idx = text.index(start_marker) + len(start_marker)
        end_idx = text.index(end_marker, start_idx)
        student_name = text[start_idx:end_idx].strip()
        return student_name
    except ValueError:
        return None

def process_word_files(source_folder, destination_folder):
    """
    This function processes all Word files in the source folder, extracts student names, 
    and moves files to new folders named after the extracted student names.
    """
    if not os.path.exists(destination_folder):
        os.makedirs(destination_folder)

    for filename in os.listdir(source_folder):
        if filename.endswith(".docx"):
            filepath = os.path.join(source_folder, filename)
            try:
                doc = Document(filepath)
                full_text = []
                for para in doc.paragraphs:
                    full_text.append(para.text)
                combined_text = "\n".join(full_text)

                student_name = extract_student_name(combined_text)
                if student_name:
                    # Create a new folder named after the student
                    student_folder = os.path.join(destination_folder, student_name)
                    if not os.path.exists(student_folder):
                        os.makedirs(student_folder)

                    # Move the Word file to the new folder
                    new_filepath = os.path.join(student_folder, filename)
                    os.rename(filepath, new_filepath)
                    print(f"Moved {filename} to {student_folder}")
                else:
                    print(f"Could not find a student name in {filename}")
            except Exception as e:
                print(f"Error processing file {filename}: {e}")

if __name__ == "__main__":
    # Define source and destination folders
    source_folder = "path/to/source/folder"  # Update this with the path to your source folder
    destination_folder = "path/to/destination/folder"  # Update this with the path to your destination folder

    # Process the Word files
    process_word_files(source_folder, destination_folder)
ackermanmoriii commented 2 months ago

Let’s walk through a simple numerical example to illustrate short-run versus long-run elasticity using the same gasoline example.

Scenario: Gasoline Prices

Now, the price increases to $4 per gallon. How do people respond in the short run versus the long run?


1. Short-Run Response

In the short run, people can’t change their habits quickly (they still need to drive the same amount).

Short-Run Elasticity Calculation

Elasticity formula:

[ \text{Elasticity} = \frac{\%\ \text{change in quantity demanded}}{\%\ \text{change in price}} ]

Step 1: Calculate the percentage change in price

[ \%\ \text{change in price} = \frac{4 - 2}{2} \times 100 = 100\% ]

Step 2: Calculate the percentage change in quantity demanded

[ \%\ \text{change in quantity demanded} = \frac{900 - 1000}{1000} \times 100 = -10\% ]

Step 3: Calculate short-run elasticity [ \text{Short-run elasticity} = \frac{-10\%}{100\%} = -0.1 ]

This tells us that in the short run, gasoline is inelastic (-0.1), meaning demand doesn’t change much when the price increases.


2. Long-Run Response

In the long run, people have time to adjust to higher prices. Over time, they start buying more fuel-efficient cars, using public transport, or moving closer to work.

Long-Run Elasticity Calculation

Step 1: Percentage change in price remains the same as before: 100% (from $2 to $4).

Step 2: Calculate the percentage change in quantity demanded

[ \%\ \text{change in quantity demanded} = \frac{700 - 1000}{1000} \times 100 = -30\% ]

Step 3: Calculate long-run elasticity [ \text{Long-run elasticity} = \frac{-30\%}{100\%} = -0.3 ]

In the long run, gasoline is more elastic (-0.3) because people have had time to make adjustments, and demand decreases more when the price increases.


Summary

This shows how people’s ability to adjust over time changes the elasticity of demand!