Page 1 of 1

Python While Loop

Posted: Wed May 29, 2024 12:58 pm
by admin
#While loop (FW01)

Code: Select all

#While loop
counter = 1

while counter <= 5:
    print(counter)
    counter += 1

Re: Python While Loop

Posted: Mon Aug 11, 2025 8:46 am
by admin

Code: Select all

# List of invoices with GST amounts
gst_amounts = [1250.50, 845.00, 999.75, 1575.20, 2020.00]

total_gst = 0
for gst in gst_amounts:
    total_gst += gst

print(f"Total GST Collected: ₹{total_gst:,.2f}")

Re: Python While Loop

Posted: Mon Aug 11, 2025 8:46 am
by admin

Code: Select all

# Outstanding amount to collect from a client
outstanding_amount = 10000
follow_up_count = 0

while outstanding_amount > 0:
    follow_up_count += 1
    print(f"Follow-up {follow_up_count}: Calling client...")

    # Simulate payment received in random chunks
    payment = int(input("Enter payment received this time: ₹"))
    outstanding_amount -= payment

    if outstanding_amount > 0:
        print(f"Remaining outstanding: ₹{outstanding_amount}\n")
    else:
        print("\n✅ Full payment received!")

print(f"Total follow-ups made: {follow_up_count}")

Re: Python While Loop excel file

Posted: Mon Aug 11, 2025 8:51 am
by admin

Code: Select all

import pandas as pd

sheets = ["Apr.xlsx", "May.xlsx", "Jun.xlsx"]

for sheet in sheets:
    print(f"Processing {sheet}...")
    df = pd.read_excel(sheet)

    mismatch_count = len(df[df['GST_Match'] == 'No'])
    
    while mismatch_count > 0:
        print(f"  Fixing {mismatch_count} mismatches in {sheet}...")
        # (simulate fixing mismatches)
        mismatch_count -= 1

    print(f"✅ {sheet} fully matched!\n")
[attachment=0]sample Sheet.zip[/attachment]