Skip to content

Instantly share code, notes, and snippets.

@BlueNexus
Last active June 12, 2025 01:51
Show Gist options
  • Save BlueNexus/599962d03a1b52a8d5f595dabd51dc34 to your computer and use it in GitHub Desktop.
Save BlueNexus/599962d03a1b52a8d5f595dabd51dc34 to your computer and use it in GitHub Desktop.
Python to Pseudocode converter
import os.path
import re
'''
INSTRUCTIONS
1. Create a file with the following code
2. Put the file you want to convert into the same folder as it, and rename it to "py_file.py"
3. Add a "#F" comment to any lines in the code which have a function call that doesn't assign anything (so no =),
as the program cannot handle these convincingly
4. Run the converter file
'''
python_file = 'py_file.py'
basic_conversion_rules = {"for": "FOR", "=": "TO", "if": "IF", "==": "EQUALS", "while": "WHILE", "until": "UNTIL",
"import": "IMPORT", "class": "DEFINE CLASS", "def": "DEFINE FUNCTION", "else:": "ELSE:",
"elif": "ELSEIF", "except:": "EXCEPT:", "try:": "TRY:", "pass": "PASS", "in": "IN"}
prefix_conversion_rules = {"=": "SET ", "#F": "CALL "}
advanced_conversion_rules = {"print": "OUTPUT", "return": "RETURN", "input": "INPUT"}
def l2pseudo(to_pseudo):
for line in to_pseudo:
line_index = to_pseudo.index(line)
line = str(line)
line = re.split(r'(\s+)', line)
for key, value in prefix_conversion_rules.items():
if key in line:
if not str(line[0]) == '':
line[0] = value + line[0]
else:
line[2] = value + line[2]
for key, value in basic_conversion_rules.items():
for word in line:
if key == str(word):
line[line.index(word)] = value
for key, value in advanced_conversion_rules.items():
for word in line:
line[line.index(word)] = word.replace(key, value)
for key, value in prefix_conversion_rules.items():
for word in line:
if word == key:
del line[line.index(word)]
to_pseudo[line_index] = "".join(line)
return to_pseudo
def p2file(to_file):
py_file = os.path.splitext(os.path.basename(python_file))[0]
with open(py_file + '_pseudo.txt', 'w') as writer:
writer.write("\n".join(to_file))
def main():
with open(python_file, 'r+') as py_file_reader:
file_lines = py_file_reader.readlines()
work_file = l2pseudo(file_lines)
p2file(work_file)
if __name__ == '__main__':
main()
@BO2MAUNG
Copy link

Hello,
Please help to change Python to simple Pseudocode below the Python code!
Thanks for your kindly support.

def process_order(order_ID, warehouse_data, vehicle_possibility, delivery_address, delivery_date):

Check if the product is in stock

if order_ID['product_id'] in warehouse_data:
print("Product in stock")
print("Order can be processed")

Check vehicle availability

if vehicle_possibility == "High":
print("Vehicles available for delivery")
print("Order will be delivered")

Assign vehicle to delivery route

vehicle = assign_vehicle_to_route()
load_product_to_vehicle(order_ID['product_id'], vehicle)

Deliver the product

while not vehicle_at_delivery_address(vehicle, delivery_address):
if vehicle_status(vehicle) == "available":
route_vehicle_to_delivery(vehicle, delivery_address)
continue_on_route(vehicle)

Unload the product at the delivery address

unload_product_at_delivery_address(vehicle, delivery_address)
update_order_status(order_ID, "Delivered")
print("Order delivered successfully")
return "Success"
else:
print("No vehicles available for delivery")
return "Failure"
else:
print("Product not in stock")
return "Failure"

Supporting functions for the process

def assign_vehicle_to_route():

Code to assign an available vehicle

vehicle = "Vehicle123" # Placeholder for actual vehicle assignment
return vehicle

def load_product_to_vehicle(product_id, vehicle):

Code to load the product into the assigned vehicle

print(f"Loading product {product_id} into {vehicle}")

def vehicle_status(vehicle):

Code to check the current status of the vehicle

return "available" # Placeholder for actual status check

def route_vehicle_to_delivery(vehicle, delivery_address):

Code to route the vehicle towards the delivery address

print(f"Routing {vehicle} to {delivery_address}")

def continue_on_route(vehicle):

Code to continue the vehicle on its delivery route

print(f"{vehicle} is en route")

def vehicle_at_delivery_address(vehicle, delivery_address):

Code to check if the vehicle has reached the delivery address

return True # Placeholder for actual check

def unload_product_at_delivery_address(vehicle, delivery_address):

Code to unload the product at the delivery address

print(f"Unloading product at {delivery_address}")

def update_order_status(order_ID, status):

Code to update the order status in the system

print(f"Order {order_ID} status updated to {status}")

Example usage

order_ID = {"order_id": "O1001", "product_id": "P001"}
warehouse_data = ["P001", "P002", "P003"]
vehicle_possibility = "High"
delivery_address = "123 Main St"
delivery_date = "2024-08-21"

result = process_order(order_ID, warehouse_data, vehicle_possibility, delivery_address, delivery_date)
print(result)

Please change to simple pseudocode

@vihashah154
Copy link

@BlueNexus I tried this and made sure everything is in the same folder and same name. There is no output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment