0% found this document useful (0 votes)
8 views5 pages

Python Algorithm Pseudocode

IT SBA - CSEC

Uploaded by

Sonia Omapersaud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Python Algorithm Pseudocode

IT SBA - CSEC

Uploaded by

Sonia Omapersaud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Algorithm: Benab Algorithm

Inputs:
- Number of buses
- For each bus:
- Registration number
- Owner's name
- Capacity
- Number of entries

Outputs:
- Breakdown of charges for each bus
- Total number of buses passing through different zones
- Total number of buses processed

Begin
Initialize variables:
totalBusesProcessed = 0
totalBusesZoneA = 0
totalBusesZoneB = 0
totalBusesZoneC = 0

Input number of buses

For each bus from 1 to number of buses


Input registration number, owner's name, capacity, number of entries
Increment totalBusesProcessed by 1

Calculate total fee:


totalFee = 100 * numberOfEntries

Calculate discount:
If capacity > 50 then
discount = 0.1 * totalFee
Else
discount = 0

Calculate total due:


totalDue = totalFee - discount

Print bus information and breakdown of charges:


Print "Bus ", busNumber, ":"
Print "Registration Number: ", registrationNumber
Print "Owner's Name: ", ownerName
Print "Capacity: ", capacity
Print "Number of Entries: ", numberOfEntries
Print "Total Fee: $", totalFee
Print "Discount: $", discount
Print "Total Due: $", totalDue

Check which zone the bus falls into based on its capacity:
If capacity > 80 then
Increment totalBusesZoneC by 1
Else if capacity > 50 then
Increment totalBusesZoneB by 1
Else
Increment totalBusesZoneA by 1
Print "Total number of buses passing through Zone A: ", totalBusesZoneA
Print "Total number of buses passing through Zone B: ", totalBusesZoneB
Print "Total number of buses passing through Zone C: ", totalBusesZoneC
Print "Total number of buses processed: ", totalBusesProcessed

End

Source code:

# Benab Algorithm Implementation in Python

# Function to calculate charges for each bus


def calculate_charges(entries, capacity):
total_fee = 100 * entries
discount = 0.1 * total_fee if capacity > 50 else 0
total_due = total_fee - discount
return total_fee, discount, total_due

# Main function
def main():
# Initialize variables
total_buses_processed = 0
total_buses_zone_A = 0
total_buses_zone_B = 0
total_buses_zone_C = 0

try:
# Input number of buses
num_buses = int(input("Enter the number of buses: "))
# Process each bus
for bus in range(1, num_buses + 1):
print(f"\nBus {bus}:")
registration_number = input("Enter registration number: ")
owner_name = input("Enter owner's name: ")
capacity = int(input("Enter capacity: "))
entries = int(input("Enter number of entries: "))

# Calculate charges
total_fee, discount, total_due = calculate_charges(entries, capacity)

# Print breakdown of charges


print("\nBreakdown of charges:")
print("Total Fee: $", total_fee)
print("Discount: $", discount)
print("Total Due: $", total_due)

# Check zone
if capacity > 80:
total_buses_zone_C += 1
elif capacity > 50:
total_buses_zone_B += 1
else:
total_buses_zone_A += 1

total_buses_processed += 1

# Print total number of buses passing through each zone and total number of buses
processed
print("\nTotal number of buses passing through Zone A:", total_buses_zone_A)
print("Total number of buses passing through Zone B:", total_buses_zone_B)
print("Total number of buses passing through Zone C:", total_buses_zone_C)
print("Total number of buses processed:", total_buses_processed)

except ValueError:
print("Please enter a valid number.")

# Execute the main function


if __name__ == "__main__":
print("Benab Algorithm Program")
print("Author: OpenAI")
print("Date created: February 28, 2024\n")
main()

You might also like