Created
June 21, 2025 08:55
-
-
Save thinkphp/d7894cdc57712b70ee9f7d75e2885c78 to your computer and use it in GitHub Desktop.
rental property details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#global data structures for property Management | |
#hardcoded property details from Table 1 (Task 2 requirement) | |
PROPERTIES = { | |
"B12-3AB": {"original_cost": 153450,"residual_mortgage": 112345}, | |
"B13-4CD": {"original_cost": 212130,"residual_mortgage": 180234}, | |
"B14-5GH": {"original_cost": 120100,"residual_mortgage": 85980}, | |
"B15-6JK": {"original_cost": 135230,"residual_mortgage": 101321}, | |
"B16-7MO": {"original_cost": 183230,"residual_mortgage": 130234} | |
} | |
# Glbobal list to store all transactions (accessible by both Task 2 and Task 3) | |
TRANSACTIONS = [] | |
def display_menu(): | |
""" | |
This is the subroutine for Main menu which will display to users 3 options to choose from, 3rd one being the Exit option. | |
The program should only terminate when option 3 is chosen. | |
""" | |
print("\n" + "="*40) | |
print(" RENTAL Management MENU") | |
print("="*40) | |
print("1. Enter rental property details") | |
print("2. Display summary data for rentals") | |
print("3. Exit") | |
print("=" * 40) | |
def property_data(): | |
""" | |
This is the subroutine option created for option 1 - Enter rental property details | |
For task 1, only an info mesage will be displayed. Further functionality will be added in next tasks, as per assignment instructions. | |
Task 2 Implementation : Subroutine for option 1 -- Enter rental property details | |
Allows user to input rent and expense transactions for properties | |
""" | |
#print("\n --- Enter Property Details ---") | |
#print("This function will be implemented in Task2") | |
#input("Press Enter to continue...") | |
print("\n" + "=" * 50) | |
print(" ENTER PROPERTY DETAILS") | |
print("=" * 50) | |
while True: | |
#Display available properties | |
print("\nAvailable Properties:") | |
print("-" * 20) | |
for property_code in PROPERTIES.keys(): | |
print(f"*{property_code}") | |
#get property code input | |
print("\nEnter property code (or type 'quit' to return to main manu") | |
property_code = input("Property Code: ").strip() # remove spaces at the beginning and at the end of the string | |
if property_code.lower() == 'quit': | |
print("Returning to main manu...") | |
break | |
#validate property code | |
if property_code not in PROPERTIES: | |
print(f"Error: '{property_code}' is not a valid property code.") | |
print("Please choose from the available properties listed above.") | |
continue | |
description = "" | |
while description.strip() == "": | |
description = input("Enter description: ").strip() # remove spaces at the beginning and at the end of the string | |
if description == "": | |
print("Error: DEscription cannot be empty. Please enter a description") | |
#get amount input with validation | |
while True: | |
try: | |
amount_str = input("Enter amount (positive for rent , negative for expenses): £") | |
amount = float(amount_str) #converteste de la siruri de caractere adica stringuri la float | |
if amount == 0: | |
print("Error: Amount cannot be zero. Please enter a valid amount.") | |
continue | |
break #valid amount entered | |
except ValueError: | |
print("Error: Please enter a valid numeric amount (e.g. 101 or -101)") | |
transaction = { | |
"property_code": property_code, | |
"description": description, | |
"amount": amount | |
} | |
TRANSACTIONS.append( transaction ) | |
#if amount is positive then we assume this is rent | |
if amount > 0: | |
print(f"OK Rent entry of £{amount: .2f} added successfully for {property_code}") | |
# otherwise we assume an expense | |
else: | |
print(f"OK Expense entry of £{abs(amount): .2f} added successfully for {property_code}") | |
while True: | |
continue_choice = input("\nDo you want to add another entry? (y/n): ").strip().lower() | |
if continue_choice in ['y', 'yes','oui','o']: #the use can enter or 'y' or 'yes' | |
break | |
elif continue_choice in ['n','no','nope']: | |
print("Return to main menu...") | |
return #exit subroutine | |
else: | |
print("Error: Please enter 'y' for yes or 'n' for no") | |
def summary_data(): | |
""" | |
This is the subroutine relevant to option 2 - Display summary rentals | |
At this stage, for task 1, it will only display an informativ message | |
""" | |
print("\n --- Property Summary ----") | |
print("This function will be implemented in task2") | |
input("Press Enter to continue...") | |
def exit_program(): | |
""" | |
This is the subroutine for option 3 - Exit | |
It is intended to display a polite goodby message and to terminate the program | |
""" | |
print("\n --- EXIT Program ----") | |
print("Thank you for using the Property REntal Management System!") | |
def get_user_choice(): | |
""" | |
Obtains and validate the user choice | |
Returns: int - valid option chosen by user (1, 2, or 3) | |
""" | |
while True: | |
try: | |
""" | |
Prompt the user to select the correct option which will then be analized and transmited to the corresponding variable of choice. | |
An intiger will be required here. | |
""" | |
choice = input("Please enter your choice (1-3): ") | |
#set the data type to intiger to build up on the program's functionality and integrity | |
choice_int = int(choice) | |
#validate if the option chosen by the user is in the correct range | |
if choice_int in [1,2,3]: | |
return choice_int | |
#inform the user of what are the valid options to navigate through the program and prompt for the correct value to be chosen | |
else: | |
print("Error: Please enter a valid option (1,2, or 3)") | |
except ValueError: | |
#manage any situation where the user might input text or any other characters, considered invalid - through an error message together with guidance on what the valid options are | |
print("Error: Please enter a valid intiger (1,2, or 3)") | |
def main(): | |
""" | |
This is the main function which is controlling the program | |
Implementing the main menu's functionality as per flowchart attached for Task 1 | |
""" | |
print("Welcome to the Rental Property Management System") | |
#main loop here | |
while True: | |
#here display the main menu | |
display_menu() | |
#Obtain the user's valid choice | |
user_choice = get_user_choice() | |
#Execute the correcponding action as per user's choice | |
if user_choice == 1: | |
#call the function | |
property_data() | |
elif user_choice == 2: | |
summary_data() | |
elif user_choice == 3: | |
exit_program() | |
break #exit the main loop | |
print("\nReturning to main menu...") | |
#Point of entry in the program, the main menu being called | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment