diff --git a/Lab-Exercises/solves/sol_1_smart_survey.py b/Lab-Exercises/solves/sol_1_smart_survey.py new file mode 100644 index 0000000..00e26b4 --- /dev/null +++ b/Lab-Exercises/solves/sol_1_smart_survey.py @@ -0,0 +1,29 @@ +name = str(input("What is your name?")) +while name == "": + name = str(input("Please enter your name: ")) + +age = int(input("How old are you? ")) +while age < 10 and age > 120: + if age > 0 and age < 10: + print("Sorry, you are too young to participate in this survey.") + exit() + elif age > 120: + print("Sorry, you have entered an invalid age.") + age = int(input("Please enter a valid age: ")) + +dev_status = bool(input("Are you a developer? (True/False) ")) +while dev_status not in [True, False]: + dev_status = bool(input("Please enter True or False: ")) + +roles = { + "Tier 1": "Admin", + "Tier 2": "Standard Executive Access", + "Tier 3": "Guest" +} + +if age < 18: + print(f"Hello {name}, you are a {roles['Tier 3']} with limited access.") +elif dev_status: + print(f"Hello {name}, you are a {roles['Tier 1']} with full access.") +else: + print(f"Hello {name}, you are a {roles['Tier 2']} with standard access.") diff --git a/Lab-Exercises/solves/sol_2_multi_cluster_IP_audit_tool.py b/Lab-Exercises/solves/sol_2_multi_cluster_IP_audit_tool.py new file mode 100644 index 0000000..0d4a39c --- /dev/null +++ b/Lab-Exercises/solves/sol_2_multi_cluster_IP_audit_tool.py @@ -0,0 +1,27 @@ +cluster_config = { + "cluster_name": "dhaka-prod-east", + "total_max_slots": 8, + "active_nodes": ["10.0.1.15", "10.0.1.16", "10.0.1.17", "10.0.1.18", "10.0.1.19"] +} + + +def calculate_capacity(config): + cluster_name = config["cluster_name"] + total_max_slots = config["total_max_slots"] + active_nodes = config["active_nodes"] + + active_nodes_count = 0 + for node in active_nodes: + active_nodes_count += bool(node) + + utilization_percentage = ( + float(active_nodes_count) / total_max_slots) * 100.00 + + print(f" ###### Audit Report for Cluster: {cluster_name} ###### ") + print(f" Total active nodes found: {active_nodes_count}") + print(f" Total max slots available: {total_max_slots}") + print(f" Utilization Percentage: {utilization_percentage:.2f}%") + print("###### End of Report ######") + + +calculate_capacity(cluster_config) diff --git a/Lab-Exercises/solves/sol_3_deploy_budget_optimizer.py b/Lab-Exercises/solves/sol_3_deploy_budget_optimizer.py new file mode 100644 index 0000000..0536bba --- /dev/null +++ b/Lab-Exercises/solves/sol_3_deploy_budget_optimizer.py @@ -0,0 +1,23 @@ +def estimate_deployment_costs(instance_count, hourly_rate_per_instance, budget_cap): + monthly_cost = instance_count * hourly_rate_per_instance * 24 * 30 + + if monthly_cost > budget_cap: + excess_amount = monthly_cost - budget_cap + return f"REJECTED: Budget Exceeded by ${excess_amount:.2f}" + + return f"APPROVED: Deployment within budget. Monthly Cost: ${monthly_cost:.2f}" + + +instance_count = 5 +hourly_rate_per_instance = 0.45 +budget_cap = 1500 + +print(estimate_deployment_costs(instance_count, + hourly_rate_per_instance, budget_cap)) + +instance_count = 12 +hourly_rate_per_instance = 0.85 +budget_cap = 10000.00 + +print(estimate_deployment_costs(instance_count, + hourly_rate_per_instance, budget_cap)) diff --git a/Lab-Exercises/solves/sol_4_profile_text_normalization_pipeline.py b/Lab-Exercises/solves/sol_4_profile_text_normalization_pipeline.py new file mode 100644 index 0000000..9440361 --- /dev/null +++ b/Lab-Exercises/solves/sol_4_profile_text_normalization_pipeline.py @@ -0,0 +1,10 @@ +raw_survey_inputs = [" ALICE SMITH ", " dhaka, BANGLADESH ", + " mLOpS_ENGineer ", " LIAM,MAYA "] +normalized_outputs = [] + +for text in raw_survey_inputs: + normalized_text = text.strip().lower().replace(",", " ").replace("_", " ") + normalized_outputs.append(normalized_text) + +print(f"Raw Input: {raw_survey_inputs}") +print(f"Sanitized Production Input: {normalized_outputs}") diff --git a/Lab-Exercises/solves/sol_5_System_Alert_Flag_Evaluator.py b/Lab-Exercises/solves/sol_5_System_Alert_Flag_Evaluator.py new file mode 100644 index 0000000..a177d9c --- /dev/null +++ b/Lab-Exercises/solves/sol_5_System_Alert_Flag_Evaluator.py @@ -0,0 +1,10 @@ +is_active = True +cpu_percent = 70 +is_production = True + +should_alert = not is_active or cpu_percent > 90.0 and is_production + +if should_alert: + print("[ALERT] Urgent dispatch! System needs manual intervention.") +else: + print("[OK] System operating within safe margin bounds.") diff --git a/Lab-Exercises/solves/solve_method.md b/Lab-Exercises/solves/solve_method.md new file mode 100644 index 0000000..f7062bd --- /dev/null +++ b/Lab-Exercises/solves/solve_method.md @@ -0,0 +1,46 @@ +## For exercise 1 +### Steps behind the solve +I solve this problem by following these steps below: + 1. At first, I ask user a question that what is his/her name and store + it in a variable as an user input. For ensuring user is not + providing blank value I use a `while` loop and warning users until + he/she does not provide any input against this question. + 2. Then I ask for the age and verify is it in between 10 to 120 years + because we don't want that our system is used by a child less than + ten, and usually no human being alive after 120 years (except some + rare cases). + 3. Then I ask for provided his developer status within boolean values that true or false. Here I also ensure that no null value is providing by users using `while` loop. + 4. Then I made a dictionary for the roles of users. + 5. Then I check those conditions using `if-elif-else` and `print` current role for the user with a greeting message. + +### Limitations +**N.B:** +Though I check null value. But user can provide any string for his name. Because there are no limitation in the name field except null or empty string. It could be a single character to thousand of characters, with this advantage any malicious user can inject payload or malicious code or script to our program and there is a high risk that it could be compromise by that. + + +## For Exercise 2 +### Steps behind the solve +1. At first, I extract data from the `config` arguments provided during the function calling. +2. Then I took a variable called `active_node_count` to store total nodes active in the cluster. +3. After that, use for loop to count and store active nodes to that variable I took above. +4. Then I calculate the utilization percentage. +5. At last, I print the report using f-string. + +## For Exercise 3 +### Steps behind the solve +1. This is a very easy and straight exercise. Here I just calculate total monthly cost and compare it. +2. Then print the status. + + +## For Exercise 4 +### Steps behind the solve +1. Here I just use `strip`, `lower` and `replace` functions to sanitized the words and store them to in a new variable called `normalized_outputs` using `append`. + +## For Exercise 5 +### Steps behind the solve +1. This was anothoer easy exercise. The critical think in this problem was this logic `not is_active or cpu_percent > 90.0 and is_production`. +2. I store the output of this logic in `should_alert` variable. +3. The I use `if-else` statement to print the message against the output of `should_alert` variable. + + +**That's All - Thank You** \ No newline at end of file