Problem-Solving (COS102)
Course Title: Problem-Solving (COS102)
Topic 1: Introduction to the Core Concepts of Computing
1.1 What is Computing?
Computing is the study and use of computer systems to process data, solve problems, and
automate tasks. It involves hardware, software, algorithms, and programming to achieve efficient
and effective solutions. Computing is the foundation of modern technology and is used in
various fields, including business, science, healthcare, and engineering.
1.2 Core Concepts of Computing
Computing consists of several fundamental concepts that guide its application in problem-
solving:
1. Data and Information Processing – Computing involves collecting, processing, storing,
and retrieving data to produce useful information.
2. Algorithms and Problem-Solving – Algorithms are step-by-step instructions that
computers follow to perform tasks. They are essential for solving problems efficiently.
3. Programming – Programming involves writing code in languages like Python, Java, and
C++ to implement algorithms and automate processes.
4. Computer Hardware and Software – Computing systems consist of physical
components (hardware) and software programs that allow them to function.
5. Networking and Communication – Computers communicate over networks to share
information and resources, leading to the development of the internet and cloud
computing.
6. Artificial Intelligence (AI) and Machine Learning – AI enables computers to learn
from data and perform intelligent tasks, such as voice recognition and image processing.
1.3 Features of Computing
Automation – Computers can perform repetitive tasks efficiently.
Speed – Computing systems process data quickly, reducing human effort.
Accuracy – Computational processes minimize errors in calculations and operations.
Versatility – Computers can be programmed to perform various tasks across different
fields.
Connectivity – Networking allows seamless communication and data sharing.
1.4 Applications of Computing
Education – E-learning platforms, online libraries, and virtual labs.
Healthcare – Medical diagnosis, patient records management, and robotic surgeries.
Business – Data analysis, automation of transactions, and online marketing.
Engineering – Computer-aided design (CAD) and simulations.
Entertainment – Video games, animation, and music production.
1.5 Example of Computing in Action
Consider an online shopping system:
A user places an order on a website (data processing).
The system calculates the price and updates the stock (algorithms).
The payment is processed securely (networking and security).
A confirmation email is sent to the user (automation).
Topic 2: Problems and Problem-Solving
2.1 What is a Problem?
A problem is a challenge or difficulty that requires a solution. Problems can be encountered in
various aspects of life, including business, science, technology, and daily activities.
2.2 Problem-Solving in Computing
Problem-solving is the process of finding solutions to complex challenges. In computing, it
involves breaking down a problem, analyzing it, and applying systematic methods to find a
solution using algorithms and programming techniques.
2.3 Steps in Problem-Solving
The process of solving problems in computing typically involves:
1. Understanding the Problem – Identify and define the issue clearly.
2. Breaking Down the Problem – Divide it into smaller, manageable parts.
3. Exploring Possible Solutions – Consider different approaches to solving the problem.
4. Choosing the Best Solution – Select the most efficient and feasible solution.
5. Implementing the Solution – Use programming languages and algorithms to develop
the solution.
6. Testing and Debugging – Identify and fix errors to ensure accuracy.
7. Evaluating the Solution – Analyze whether the solution meets the required needs.
2.4 Features of Effective Problem-Solving
Logical Reasoning – Ability to approach problems systematically.
Creativity – Thinking of innovative solutions.
Analytical Thinking – Evaluating different aspects of the problem.
Persistence – The ability to refine and optimize solutions.
2.5 Applications of Problem-Solving in Computing
Software Development – Writing efficient programs to automate tasks.
Cybersecurity – Identifying and fixing security vulnerabilities.
Data Analysis – Using algorithms to extract useful insights from data.
Artificial Intelligence – Training machines to solve problems independently.
2.6 Example of Problem-Solving in Computing
A banking application may need to detect fraudulent transactions. The problem-solving process
would involve:
Identifying patterns of fraudulent activity.
Designing an algorithm to flag suspicious transactions.
Implementing the algorithm in a banking system.
Testing and refining the solution for better accuracy.
Real-World Example of Problem-Solving in Computing
Scenario: A Website is Loading Too Slowly
Imagine you have a website, but when people visit it, it takes a long time to load. This is a
problem because users might leave before the website even opens.
Step-by-Step Problem-Solving Approach
1. Identify the Problem:
The website takes too long to load.
Users complain or leave before the page opens.
2. Gather Information:
Use tools like Google PageSpeed Insights or GTmetrix to analyze loading speed.
Check internet connection speed.
Inspect the website’s code for large images, too many scripts, or unnecessary elements.
3. Develop Possible Solutions:
Reduce image sizes (compress them).
Minimize or remove unnecessary JavaScript and CSS files.
Enable browser caching so that returning visitors load pages faster.
Use a Content Delivery Network (CDN) to load content from servers closer to users.
4. Implement a Solution:
Compress large images using tools like TinyPNG.
Minify JavaScript and CSS to remove extra spaces and comments.
Enable caching through the website’s settings.
5. Test the Solution:
Reload the website and check if it opens faster.
Use speed test tools again to confirm improvements.
6. Evaluate and Maintain:
If the speed is still slow, try other solutions like upgrading the web hosting plan.
Regularly monitor the website to ensure it stays fast.
Outcome:
By following this structured problem-solving approach, the website becomes faster, improving
user experience and keeping visitors engaged.
This example demonstrates how computing professionals approach problems logically and
systematically. Would you like a different example, maybe in programming or cybersecurity? 😊
Topic 3: The Identification of Problems and Types of Problems
3.1 Identifying Problems
Identifying a problem is the first step in problem-solving. A well-identified problem should be:
Clearly defined – The issue must be understood in detail.
Measurable – The impact of the problem should be quantifiable.
Feasible to solve – A solution must be achievable within available resources.
3.2 Types of Problems
Problems can be categorized based on complexity and how frequently they occur:
3.2.1 Routine Problems
Routine problems are common and occur frequently in similar conditions. These problems often
have predefined solutions and can be solved using standard procedures or algorithms.
Features of Routine Problems:
Occur regularly and have predictable solutions.
Solved using well-defined procedures.
Require minimal creativity as solutions are standard.
Examples of Routine Problems in Computing:
Sorting a list of numbers.
Searching for an item in a database.
Logging into a system using a username and password.
Application of Routine Problem-Solving:
Automated customer service bots use predefined responses to handle common
inquiries.
Sorting algorithms like Bubble Sort and Quick Sort organize data efficiently.
3.2.2 Non-Routine Problems
Non-routine problems are complex and do not have a straightforward solution. They require
creative thinking, experimentation, and new strategies to solve.
Features of Non-Routine Problems:
Require critical thinking and innovation.
Solutions are not immediately obvious.
May involve trial and error to find the best approach.
Examples of Non-Routine Problems in Computing:
Developing an artificial intelligence system that mimics human speech.
Creating a new encryption algorithm to protect online transactions.
Designing a software system that can predict disease outbreaks.
Application of Non-Routine Problem-Solving:
Machine Learning algorithms are trained to detect fraudulent activities dynamically.
Cybersecurity experts develop new methods to counter emerging cyber threats.
4.0 Methods of Solving Computing Problems (Introduction to Algorithms and Heuristics)
Computing problems are solved using structured approaches that ensure efficiency and accuracy.
Two primary methods for solving problems in computing are algorithms and heuristics. These
methods are used based on the nature of the problem, required efficiency, and available
computational resources.
4.1 Algorithms: A Structured Approach to Problem-Solving
An algorithm is a well-defined, step-by-step procedure or set of rules used to solve a specific
problem. It is a fundamental concept in computer science and serves as the basis for
programming and computation.
Features of an Algorithm
A good algorithm should have the following properties:
Input – It takes zero or more inputs.
Output – It provides at least one output.
Definiteness – Each step must be clearly and precisely defined.
Finiteness – The algorithm must terminate after a finite number of steps.
Correctness – It must solve the problem correctly.
Efficiency – It should be optimized for time and space.
Applications of Algorithms
Algorithms are widely used in:
Sorting and Searching (e.g., Bubble Sort, Binary Search)
Data Processing (e.g., Compression, Encryption)
Artificial Intelligence (e.g., Machine Learning Algorithms)
Graph Traversal (e.g., Dijkstra’s Algorithm for shortest path)
Example: Algorithm to Find the Sum of Two Numbers
1. Start
2. Input two numbers
3. Add the numbers
4. Display the sum
5. Stop
Python Implementation
# Define a function named add_numbers that takes two parameters: a and b
def add_numbers(a, b):
# Return the result of adding a and b
return a + b
# Ask the user to input the first number, convert it from string to integer, and store in variable
num1
num1 = int(input("Enter first number: "))
# Ask the user to input the second number, convert it from string to integer, and store in variable
num2
num2 = int(input("Enter second number: "))
# Call the add_numbers function with num1 and num2 as arguments,
# then print the result with a message
print("The sum is:", add_numbers(num1, num2))
4.2 Heuristics: An Approximate Approach to Problem-Solving
A heuristic is a problem-solving method that finds a satisfactory solution where finding an
optimal solution is impractical due to complexity or time constraints. Unlike algorithms,
heuristics do not guarantee a perfect solution but aim to find a "good enough" solution quickly.
Features of Heuristics
Speed – Provides a fast solution rather than an optimal one.
Flexibility – Can be applied to a wide range of problems.
Trade-off between accuracy and efficiency – May not guarantee correctness.
Applications of Heuristics
Artificial Intelligence – Used in decision-making systems.
Game Playing – Chess engines use heuristics to evaluate board positions.
Route Optimization – GPS systems use heuristics for traffic-aware routing.
Scheduling Problems – Used in job scheduling and resource allocation.
Example: Heuristic Approach in Route Optimization
Instead of evaluating every possible path in a city, a heuristic approach might prioritize:
Shortest distance first
Avoiding high-traffic areas
Preferring highways over local roads
5.0 Solvable and Unsolvable Problems in Computing
Not all problems in computing have a solution. Problems are classified into solvable and
unsolvable categories based on whether an algorithm exists that can provide an answer within
finite time and resources.
5.1 Solvable Problems
A solvable problem is one for which an algorithm can be designed to provide a correct solution
within a reasonable amount of time and space.
Examples of Solvable Problems
Sorting Numbers – Sorting a list of numbers using the Quick Sort algorithm.
Pathfinding – Finding the shortest route using Dijkstra’s algorithm.
Data Compression – Reducing file size using Huffman coding.
Matrix Multiplication – Performing mathematical operations on matrices.
Python Example: Solving the Sorting Problem Using Bubble Sort
# Define a function called bubble_sort that takes a list 'arr' as input
def bubble_sort(arr):
# Get the number of elements in the list
n = len(arr)
# Outer loop runs n times to make sure all elements are sorted
for i in range(n):
# Inner loop goes from 0 to n-i-1
# This ensures that with each pass, the largest element "bubbles up" to the end
for j in range(0, n-i-1):
# Compare the current element with the next one
if arr[j] > arr[j+1]:
# If current element is greater, swap them
arr[j], arr[j+1] = arr[j+1], arr[j]
# This is called tuple unpacking — a neat way to swap values
# After sorting is done, return the sorted list
return arr
# Define a list of unsorted numbers
numbers = [64, 25, 12, 22, 11]
# Call the bubble_sort function and store the sorted list in 'sorted_numbers'
sorted_numbers = bubble_sort(numbers)
# Print the result
print("Sorted list:", sorted_numbers)
5.2 Unsolvable Problems
An unsolvable problem is a problem for which no algorithm can be written to provide a correct
solution in all cases. These problems usually arise in computability theory, where a problem
cannot be solved using any computational model.
Examples of Unsolvable Problems
The Halting Problem – Determining whether a given program will eventually stop or
run forever is undecidable.
Tiling Problem – Given a set of tiles, deciding whether they can perfectly tile an infinite
plane is an unsolvable problem.
Post Correspondence Problem (PCP) – A decision problem that cannot be solved
algorithmically.
The Halting Problem (Proven Unsolvable by Alan Turing)
The halting problem asks whether a given program will terminate or continue to run indefinitely.
Turing proved that it is impossible to write a program that can determine this for all cases.
Python Representation of an Unsolvable Problem (Halting Problem Simulation)
def will_halt(program, input_value):
try:
exec(program)
return "Program halts"
except:
return "Program runs indefinitely"
program_code = """
while True:
pass # Infinite loop
"""
print(will_halt(program_code, None))
Explanation: The function tries to execute the given program, but if it contains an infinite loop,
it will never stop, making it an unsolvable problem.
Conclusion
Problem-solving in computing is achieved through well-structured algorithms and approximate
heuristic methods. While many problems are solvable with algorithms, some remain unsolvable
due to their inherent complexity. Understanding these classifications helps computer scientists
develop efficient computational solutions and recognize the limits of computation.
TOPIC 6: SOLUTION TECHNIQUES FOR SOLVING PROBLEMS
Problem-solving is a fundamental skill in computer science, where various techniques are used to
analyze and resolve complex issues. Selecting the right solution technique depends on the nature
of the problem. This note explores different solution techniques, their features, applications, and
examples.
1. Abstraction
Abstraction is the process of simplifying a complex problem by removing unnecessary details
and focusing on the essential aspects.
Features
Helps in managing complexity.
Focuses on relevant details while ignoring irrelevant ones.
Commonly used in programming and software design.
Applications
In object-oriented programming (OOP), classes and objects abstract real-world entities.
In database design, abstraction is used in different schema levels (Conceptual, Logical,
Physical).
Example
When designing a mobile app, abstraction helps focus on core functions like user interface and
data handling, without worrying about the hardware details.
2. Analogy
Analogy involves solving a problem by finding a similar past problem and applying its solution
to the current issue.
Features
Encourages pattern recognition.
Uses past experiences to solve new problems.
Common in artificial intelligence and machine learning.
Applications
Used in AI for case-based reasoning.
Applied in engineering to develop new technologies by modifying existing ones.
Example
The structure of an airplane’s wings was inspired by birds' wings, using the analogy of flight
dynamics.
3. Brainstorming
Brainstorming is a group or individual problem-solving technique where multiple ideas are
generated to find the best possible solution.
Features
Encourages creative and out-of-the-box thinking.
Focuses on idea quantity before filtering for quality.
Used in business, software development, and research.
Applications
Software development teams brainstorm to generate innovative app features.
Business teams brainstorm to create marketing strategies.
Example: A development team brainstorming ideas for a new mobile banking application.
4. Trial and Error
Trial and error, is a method of solving a problem by repeatedly testing different solutions until
the correct one is found.
Features
Simple and intuitive.
Can be time-consuming and inefficient for complex problems.
Commonly used in learning and scientific research.
Applications
Debugging code in programming.
Chemical experiments in laboratories.
Example
A programmer debugging a software error by modifying code multiple times until it runs
correctly.
5. Hypothesis Testing
Hypothesis testing involves formulating an assumption (hypothesis) and testing it through
experiments or observations.
Features
Involves collecting and analyzing data.
Uses statistical methods to validate or reject hypotheses.
Commonly used in research and decision-making.
Applications
Used in AI and machine learning to train models.
In business, used for market research and trend analysis.
Example
A data scientist testing whether an increase in social media ads improves product sales.
6. Reduction
Reduction simplifies a complex problem by breaking it down into a simpler equivalent problem
that is easier to solve.
Features
Converts difficult problems into well-known solvable ones.
Used in mathematics and computing.
Efficient for optimization problems.
Applications
Used in algorithm design to reduce complex computations.
Applied in cryptography for breaking down encryption techniques.
Example
A complex image processing problem is reduced to a simpler matrix manipulation problem.
7. Literal Thinking
Literal thinking focuses on a direct and logical approach to solving problems without
assumptions or abstract interpretations.
Features
Straightforward and structured.
Avoids subjective interpretation.
Commonly used in programming and legal reasoning.
Applications
Writing clear and explicit software code.
Legal contracts that require precise wording.
Example
A programmer follows exact specifications in writing a sorting algorithm.
8. Means-End Analysis
Means-end analysis involves comparing the current state of a problem with the desired goal and
determining the best way to close the gap.
Features
Involves setting subgoals to reach the main goal.
Used in artificial intelligence and robotics.
Helps in planning and decision-making.
Applications
Used in game AI to plan moves in chess.
Applied in navigation systems to find the shortest route.
Example
A GPS system determines the shortest path to a destination by comparing the current location
with the target location.
9. Method of Focal Object
This technique involves taking an unrelated object and combining its characteristics with the
problem to generate creative solutions.
Features
Encourages innovation.
Commonly used in product design and engineering.
Helps in creative problem-solving.
Applications
Used in industrial design for new product innovations.
Applied in marketing for unique advertising campaigns.
Example
Using the design of a fish’s gills to develop better air filtration systems.
10. Morphological Analysis
Morphological analysis involves systematically examining all possible solutions to a problem by
considering multiple dimensions and variations.
Features
Uses a structured framework.
Effective for complex problems with multiple factors.
Applied in engineering, business strategy, and innovation.
Applications
Used in mechanical engineering for new product designs.
Applied in business strategy to evaluate market scenarios.
Example
A car company analyzing various engine, body, and fuel types to design a new vehicle.
11. Research
Research involves systematically gathering information, analyzing data, and evaluating evidence
to solve a problem.
Features
Relies on data and factual evidence.
Involves detailed study and analysis.
Common in academia and business.
Applications
Scientific discoveries and technological advancements.
Business market analysis and consumer behavior research.
Example
A researcher studies user feedback to improve an e-commerce website.
12. Root Cause Analysis (RCA)
Definition
Root cause analysis focuses on identifying the underlying reason for a problem rather than just
addressing symptoms.
Features
Provides long-term solutions.
Helps prevent recurrence of problems.
Used in engineering, healthcare, and software development.
Applications
Debugging software errors by tracing the root cause.
Identifying safety hazards in workplaces.
Example
A network administrator traces repeated system failures to a faulty server component.
13. Proof
Proof is the process of logically verifying the correctness of a solution using mathematical or
formal reasoning.
Features
Ensures correctness and reliability.
Used in theoretical computer science and cryptography.
Helps in validating algorithms.
Applications
Proving the correctness of an encryption algorithm.
Mathematical proofs in algorithm complexity analysis.
Example
Verifying that a sorting algorithm correctly arranges numbers in ascending order.
14. Divide and Conquer
Divide and conquer is a problem-solving technique that breaks a large problem into smaller,
independent subproblems, solves them individually, and then combines the solutions to solve the
original problem.
Features
Improves efficiency.
Used in recursive algorithms.
Common in computer science and engineering.
Applications
Sorting algorithms like Merge Sort and Quick Sort.
Parallel computing and distributed systems.
Example
Sorting a large dataset using Merge Sort, which divides the dataset into smaller sorted segments
and merges them. Below are more practical examples of divide and conquer problem solving
technique.
1. Troubleshooting Technical Issues
Example: Your Wi-Fi isn't working.
Divide: Break the system down — is the router working? Is the modem connected to the
internet? Is it a device-specific issue?
Conquer: Test each component individually.
Combine: Once the faulty part is found, fix or replace it, restoring the whole system.
2. Cleaning a Messy House
Example: Cleaning an entire messy house can feel overwhelming.
Divide: Break it down by room or even by tasks (dusting, vacuuming, organizing).
Conquer: Tackle each room or task one at a time.
Combine: At the end, the whole house is clean.
3. Cooking a Complex Meal
Example: Preparing a Thanksgiving dinner.
Divide: Break the meal down into dishes: turkey, stuffing, pie, salad.
Conquer: Assign dishes to different people or prepare each separately.
Combine: Serve everything together at dinner.
4. Project Management
Example: Building a website or launching a product.
Divide: Break into teams or components — frontend, backend, content, marketing.
Conquer: Each team works on their piece.
Combine: Integrate all parts into the final product.
Topic 7: General Problem-Solving Process
Problem-solving is the backbone of computer science. It involves identifying a problem,
analyzing it, and developing a systematic solution, typically with the help of algorithms and
computational thinking. Whether you’re writing a program, designing a system, or debugging an
error, effective problem-solving skills are essential. The General Problem-Solving Process is a
systematic approach that guides scientists, engineers, and developers to tackle problems
efficiently and logically.
Steps in the Problem-Solving Process
The general problem-solving process can be broken down into 6 core steps:
1. Understanding the Problem (What exactly are we trying to solve?)
Goal: Grasp the nature and scope of the problem.
Tasks:
Read and interpret the problem statement.
Identify inputs and outputs.
Recognize constraints and requirements.
Example: For a program that finds the largest number in a list, understand:
Input: List of numbers.
Output: Largest number.
Constraints: Can the list be empty? Are there negative numbers?
2. Analyzing the Problem (What information do we have and what do we need?)
Goal: Break the problem into components and study relationships.
Tasks:
Identify knowns and unknowns.
Determine data types and structures needed.
Consider edge cases and special conditions.
Example: Analyze if the list contains duplicates, how large it can be, and whether sorting is
necessary.
3. Designing the Algorithm (How do we solve it step-by-step?)
Goal: Create a clear and logical method to solve the problem.
Tasks:
Choose a problem-solving strategy (e.g., brute force, divide and conquer, greedy, dynamic
programming).
Write pseudocode or flowcharts.
Focus on simplicity, clarity, and efficiency.
Example: For finding the largest number:
Initialize a variable to store the maximum.
Loop through the list.
Compare and update the maximum.
4. Implementing the Solution (Let’s write the code!)
Goal: Translate the algorithm into a programming language.
Tasks:
Choose the right language (Python, Java, C++, etc.).
Follow proper syntax, conventions, and structure.
Use functions and modular code.
Best Practices:
Write clean and readable code.
Use meaningful variable names.
Handle possible errors or exceptions.
5. Testing and Debugging (Does it work as expected?)
Goal: Ensure the solution works correctly and efficiently.
Tasks:
Test with normal, edge, and extreme cases.
Debug and fix logical, runtime, or syntax errors.
Use tools like IDEs, debuggers, or print statements.
Example: Test the largest number program with:
Positive numbers, negative numbers, and an empty list.
Large lists to check performance.
6. Evaluating and Improving the Solution (Can we make it better?)
Goal: Analyze and optimize the solution.
Tasks:
Evaluate time and space complexity (Big-O notation).
Refactor for clarity and performance.
Consider alternative solutions or trade-offs.
Problem-Solving Strategies in Computer Science: Below are common strategies used during
the problem-solving process:
Strategy Description Example Use
Brute Force Try all possible solutions. Generating all subsets of a set.
Coin change problem
Greedy Make the best local choice at each step.
(sometimes).
Divide and Conquer Break problem into subproblems, solve Merge Sort, Binary Search.
Strategy Description Example Use
recursively.
Dynamic Fibonacci sequence, Knapsack
Solve subproblems and store results.
Programming problem.
Try solutions and backtrack when you hit Sudoku solver, N-Queens
Backtracking
a dead-end. problem.
Real-Life Analogy: Think of problem-solving like planning a trip:
Understand the goal: Decide where you want to go.
Analyze the details: Check the budget, distance, time.
Design the route: Choose transportation and stops.
Implement: Book tickets, pack bags.
Test: Check weather, delays, or detours.
Evaluate: Was the trip efficient, enjoyable, cost-effective?
Importance in Computer Science
i. Software Development: Every program solves a problem.
ii. Competitive Programming: Requires fast and optimal problem-solving.
iii. Artificial Intelligence: Solves complex, uncertain problems.
iv. Systems Design: Breaks large systems into manageable parts.
v. Data Science: Analyzes and processes data efficiently.
Example: Solving a Simple Problem
Write a program to calculate the sum of two numbers entered by the user.
Step 1: Understand the Problem
What is the problem asking?
We need to add two numbers and show the result.
Input: Two numbers (from the user).
Output: The sum of those two numbers.
Step 2: Analyze the Problem
Think about:
What kind of numbers? (Whole numbers, decimals?)
How will the user enter them? (One at a time? Together?)
What happens if the user types a word instead?
For simplicity, let’s assume:
The numbers are whole numbers (integers).
The user will input them one at a time.
We won’t handle input errors for now.
Step 3: Design the Solution
Plan the steps:
Ask the user to enter the first number.
Ask for the second number.
Add the two numbers.
Show the result.
You can write this in pseudocode (plain English):
Start
Ask user for number1
Ask user for number2
Add number1 and number2
Show the result
End
Step 4: Implement the Solution
Now, write the actual code in a programming language (let's use Python):
# Get input from the user
num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))
# Add the numbers
sum = num1 + num2
# Show the result
print("The sum is:", sum)
Step 5: Test the Solution
Try a few test cases:
Input: 4 and 5 → Output: The sum is: 9
Input: 0 and 0 → Output: The sum is: 0
Input: -3 and 10 → Output: The sum is: 7
Step 6: Evaluate and Improve
Can we make it better?
Yes! We could:
Allow decimal numbers by using float() instead of int().
Add error handling (what if the user types “apple”?)
Make it reusable by turning it into a function.
Final Version (Improved)
def add_two_numbers():
try:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
print("The sum is:", num1 + num2)
except ValueError:
print("Please enter valid numbers!")
add_two_numbers()