Python Algorithm Pseudocode
Python Algorithm Pseudocode
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
Calculate discount:
If capacity > 50 then
discount = 0.1 * totalFee
Else
discount = 0
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:
# 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)
# 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.")