DEV Community

Cover image for Python3 Programming - Exercise 5 b - Design Solution
Michael Otu
Michael Otu

Posted on • Edited on

Python3 Programming - Exercise 5 b - Design Solution

Design a solution

continuation of exercise 5 a (Analysis of a solution)

In this phase, we try to put together the information we gathered from the analysis we made. Here we may provide a human-readable solution that would be used to implement the solution. Again, we decide what data types and data structures that would be used. So here, we could let the average score be an integer or a float and keep all the test scores in an array ( here a list). What should come in mind is pseudo code ( a.k.a false code). From the analysis we can say:

Solution design with false code

label: type we used is what we discussed in Exercise 2 ( Datatypes) - Type hinting

Note

  • Most of these stages are done together because this is a small problem - which we could even implement straight forward
  • Remember, it is easier to implement a solution after we have analyzed and chose which approach of the solution gave us the desired outcome, efficiently. This means, there could be more than one solution to solve the problem.

Practicals

Tip: look out for the given inputs ( the available parameters), the desired outputs ( what is expected), and the process ( how to get the output).

Analyze and design a solution for the following problems.

  1. Given that a quadratic equation is of the form, Ax^2 + Bx + C = 0 , where A , B , C are real parameters such that A , B is not zero. A and B are the coefficients of x, of second and first degrees respectively and c a constant. Find and output the roots of the quadratic equation.

  2. Find the Area of a circle of radius, r, given that PI is 3.143.

  3. A shop keeper sold an item of cost, $340.00 at $372.99 including a tax of $2.99 .find the

    • selling price
    • profit made
    • profit percentage
    • tax percentage

Summary

  • To analyze the problem, look out for the input, output and the process
  • In the design stage, we choose what data type a value should be or be returned and a data structure, suitable to hold these values
  • We choose a solution that best gives the desired outcome
  • The best design is simple and readable

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

Top comments (0)

Tiger Data image

🐯 🚀 Timescale is now TigerData: Building the Modern PostgreSQL for the Analytical and Agentic Era

We’ve quietly evolved from a time-series database into the modern PostgreSQL for today’s and tomorrow’s computing, built for performance, scale, and the agentic future.

So we’re changing our name: from Timescale to TigerData. Not to change who we are, but to reflect who we’ve become. TigerData is bold, fast, and built to power the next era of software.

Read more

👋 Kindness is contagious

Explore this insightful piece, celebrated by the caring DEV Community. Programmers from all walks of life are invited to contribute and expand our shared wisdom.

A simple "thank you" can make someone’s day—leave your kudos in the comments below!

On DEV, spreading knowledge paves the way and fortifies our camaraderie. Found this helpful? A brief note of appreciation to the author truly matters.

Let’s Go!