Python Programming: Admin Functions and Customer Management, Study notes of Computer Science

Python functions for admin tasks such as updating prices, managing customers, and generating parcel numbers. It includes functions for assigning roles, displaying price tables, adding and modifying customers, and viewing customers and parcels by date and destination.

Typology: Study notes

2023/2024

Available from 02/24/2024

CyberSensei
CyberSensei 🇲🇾

4 documents

1 / 87

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PROGRAMMING WITH PYTHON
 
Group Assignment 
TECHNOLOGY PARK MALAYSIA 
PYTHON PROGRAMMING 
Table of Contents
INTRODUCTION AND ASSUMPTIONS............................................................................................... 2
INTRODUCTION.......................................................................................................................... ....... 2
ASSUMPTIONS........................................................................................................................... ......... 3
DESIGN OF THE PROGRAM........................................................................................................... ..... 4
PSEUDOCODE.......................................................................................................................... ........... 4
SCREENSHOTS OF SAMPLE INPUT/OUTPUT AND EXPLANATIONS...................................... 51
STUDENT 1 - ADMINISTRATOR&1............................................................................................ ..... 51
STUDENT 2 – ADMINISTRATOR&2.................................................................................................59
STUDENT 3 - OPERATOR 1........................................................................................................ ..... 67
STUDENT 4 - OPERATOR&2........................................................................................................ ..... 76
CONCLUSION........................................................................................................................................ 84
REFERENCES.................................................................................................................................. ...... 85
GROUPASSIGNMENT 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57

Partial preview of the text

Download Python Programming: Admin Functions and Customer Management and more Study notes Computer Science in PDF only on Docsity!

Group Assignment

TECHNOLOGY PARK MALAYSIA

PYTHON PROGRAMMING

Table of Contents

INTRODUCTION AND ASSUMPTIONS ............................................................................................... 2 INTRODUCTION ................................................................................................................................. 2 ASSUMPTIONS .................................................................................................................................... 3 DESIGN OF THE PROGRAM ................................................................................................................ 4 PSEUDOCODE ..................................................................................................................................... 4 SCREENSHOTS OF SAMPLE INPUT/OUTPUT AND EXPLANATIONS ...................................... 51 STUDENT 1 - ADMINISTRATOR 1 ................................................................................................. 51 STUDENT 2 – ADMINISTRATOR 2 ................................................................................................. 59 STUDENT 3 - OPERATOR 1 ............................................................................................................. 67 STUDENT 4 - OPERATOR 2 ............................................................................................................. 76 CONCLUSION ........................................................................................................................................ 84 REFERENCES ........................................................................................................................................ 85

INTRODUCTION AND ASSUMPTIONS

INTRODUCTION

Our group's collective work resulted in the development of a dynamic Python application targeted at modernizing billing methods in the field of package delivery services. This new application is a critical tool, allowing customers to deliver several items to various locations inside a consolidated consignment. This application painstakingly computes the correct cost for each unique parcel using a meticulously built price table that takes into account various weights and destination zones, assuring accuracy and transparency in the billing process. This multifaceted program is designed to offer a comprehensive array of functionalities, notably including the seamless entry and management of client information, the precise computation of parcel costs aligned with the established pricing table, the streamlined generation of consignment bills, and the facilitation of a systematic review process for generated bills. Notably, the system is meticulously structured to accommodate two distinctive user roles, each endowed with specialized functionalities tailored to their specific responsibilities within the parcel delivery service framework. The Administrator role boasts privileged access, enabling the management of critical system components, while the Operator role facilitates the execution of essential operational tasks necessary for smooth consignment handling and billing procedures. By implementing this program, our group aims to significantly enhance the operational efficiency and accuracy within the parcel delivery business sphere. This initiative not only embodies the fusion of our collective expertise in Python programming but also underscores our commitment to innovating and optimizing systems crucial to modern logistics operations.

DESIGN OF THE PROGRAM

PSEUDOCODE

ADMINISTRATOR 1

START

Set users to an empty list. Define admin_login(username, password) function. Set admin_usernames = [‘admin1987avoger1’, ‘admindarkmattervenus’] Set admin_passwords = [‘z2Qv0GW6(%P’ , ‘2251f4dKQ]}Z’] Return True If (username, password) = admin_usernames and admin_passwords. Else Return False END_IF END Function Define operator_login(username, password) function Set operator_usernames = [‘operatorinsideputnix’, ‘operatorcityofgodfly’] Set operator_passwords = [‘036_XNZipSI’, ‘d8Xt3J1SC&v9’]

Return True If (username, password) = operator_usernames and operator_passwords. Else Return False END_IF END Function Define add_user(username, password) function For each user in users If user[‘username’] = ‘username’ Print” User already exists.” Return END_IF END_FOR Create a new dictionary with keys ‘username’, ‘password’ and ‘role’ set to ‘operator’. Append the new user to users. Call save_to_file( ) function Print” User has been added as an operator.” END Function Define delete_user(username) function. For user in users

Define remove_administrator_role(username) function. For user in users If user[‘username’] = ‘username’ and user[‘role’] = ‘administrator’ Set user[‘role’] = ‘operator’ Call save_to_file( ) function Print” User has been set to operator role.” Return Else: Print” User not found or it is not an administrator.” END_IF END_FOR END Function Define view_users(role=None) function. If role = None Print” List of all users:” For user in users Print” {user[‘username’]}. {user[‘role’]} Elif role = ‘operator’ Print“ List of all operators” For user in users If user[‘role’] = ‘operator’

Print” {user[‘username’]}. {user[‘role’]}” END_IF Elif role = ‘administrator’ Print” List of all administrators.” For user in users If user[‘role’] = ‘administrator’ Print” {user[‘username’]}. {user[‘role’]}” END_IF Elif role = ‘all’ Print” List of all users.” For user in users Print” {user[‘username’]}. {user[‘role’]}” Else: Print” No users found in role ‘{role}’ or invalid role provided. END_IF END Function Define save_user_to_file( ) function Open user_operators.txt file in write mode. For each user in users, Write user[‘username’], user[‘password’] and user[‘role’] to the file. Close the file. END Function

Write the first element of the row to the file. For each column in the row Write a ‘,’ and the column value to the file. END_FOR Write a newline character. END_FOR For each row in table, If row is not empty, Write row to the file For each col in row, Write ',' followed by col to the file END_FOR Write a newline character to the file END_IF ENF_FOR END Function Define load_data_from_file( ) function Process try Initialize loaded_prices as an empty list Open prices.data.txt file in read mode.

If file exists Read each line from the file. For each line Append the list of values to loaded_prices Return loaded prices. Elif an exception occurs during file reading or data processing, Print” Error occurred while loading data.” Return an empty list. Elif loaded data is empty, Initialize table_content with default data for prices. Else: Return an empty list. END_IF END Function

Loading data from the file or initializing if it's not loaded

Load table_content from load_data_from_file() function If not table content table_content = [ ["Destination", "Weight below 1kg", "Weight in between 1kg to 3kg", "Weight more than 3kg"], ["Zone A", "RM8.00", "RM16.00", ""], ["Zone B", "RM9.00", "RM18.00", ""],

If zone != valid_zones Print” Invalid zone. Please enter a valid zone (A, B, C, D, E)” Else: Break END_IF END While WHILE True DO TRY INPUT price IF price < 0 THEN OUTPUT "Price cannot be negative. Please enter a non- negative price." ELSE BREAK END_IF CATCH ValueError DO OUTPUT "Invalid input. Please enter a valid numeric price." END_TRY END_WHILE For row in table If row corresponds to the entered zone and the price column is empty

Print” Price for this zone already exists. Return table. END_IF END_FOR For row in table If row corresponds to the entered zones and the price column is not empty Print” Price added.” Return table. END_IF END_FOR END Function Define modifying_price(table) function Print” Please note that you may only delete the price of parcels more than 3KG.” Define valid_zones = [“A”, “B”, “C”, “D”, “E”] While TRUE: Input zone and convert it into upper case. Input zone to update (A, B, C, D, E). If zone != valid_zones Print” Invalid zones. Please enter a valid zone. (A, B, C, D, E) Else:

Print” Price updated!” END_FOR END Function Define delete_price(table) Print” Please note that you may only delete the price of parcels more than 3KG.” Defines valid_zones = [‘A’, ‘B’, ‘C’, ‘D’, ‘E’] While TRUE: Input zone and convert it into upper case. Enter zone to delete (A, B, C, D, E). If != valid_zones Print” Invalid zone entered. Please enter a valid zone.” Else: Break END While For row in table If the row corresponds to the entered zone Set the price column to empty. Call save_table_data_to_file(table) function. Print “Price deleted!” Return

END_IF

END_FOR

END Function Define checking_price(table) Input zone. Enter zone to check price. Input weight. Enter weight to check price. For row in table If row = zone If weight < 1 print” Price for ‘weight’ kg parcel to ‘zone’: ‘row’” Return Elif 1<= weight <= 3 Print” Price for ‘weight’ kg parcel to ‘zone’: ‘row’” Return Else: Print” Price for ‘weight’ kg parcel to ‘zone’: ‘row’” Return END_IF END_FOR END Function

Print"2. Modify Price of Parcel" Print"3. Delete Price of Parcel" Print"4. Check Price of Parcel" Print"5. View Prices for All Parcels" Print"6. Exit" Input choice. If choice == 1: Set table_content = adding_price_above_3kg(table_content) function Call save_table_data_to_file(table_content) function Elif choice == 2: Call modifying_price(table_content) function Call save_table_data_to_file(table_content) function Elif choice == 3: Call delete_price(table_content) function Call save_table_data_to_file(table_content) function Elif choice == 4: Call checking_price(table_content) function Elif choice == 5: Call view_all_prices() function Elif choice == 6: Call save_table_data_to_file(table_content) function

Print “Bye!" Return Else: Print “Invalid choice. Please choose a number between 1 and 6." END_IF END While Define operators( ) function Define load_data_from_file( ) funtion Process try Initialize loaded_prices as an empty list Open prices_data.txt file in read mode. If file exists Read each line from the file. For each line Remove leading/trailing whitespaces and split by “,” to create a list of values. Append the list of values to loaded_prices. Return loaded_prices Elif an exception occurs during file reading or data processing Print” Error occurred while loading data.” Else: Return an empty list. END_IF