Python While Loop

Post Reply
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Python While Loop

Post by admin »

#While loop (FW01)

Code: Select all

#While loop
counter = 1

while counter <= 5:
    print(counter)
    counter += 1
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Re: Python While Loop

Post 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}")
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Re: Python While Loop

Post 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}")
admin
Site Admin
Posts: 119
Joined: Fri May 10, 2024 2:46 pm
Location:

Re: Python While Loop excel file

Post 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]
Attachments
sample Sheet.zip
SAmple
(15.14 KiB) Downloaded 17 times
Post Reply