Start learning free

LESSON 71 OF 410 · STRINGS I

Top K Brands V1 - One Brand in Python

Practice

E-commerce search page: when a shopper searches a product, show the top-rated brand selling it. In v1 there's just one product and one brand.

You start with:

product = "Laptop"
brand = "TechPro"
rating = 4

Build:

Laptop
1. TechPro (4)

Rules:

  • The first line is the product name.
  • The second line is a ranked entry written as "1. Brand (rating)".
  • Keep each line in its own variable (product_line and brand_line), then join them with "\n" into one string called output.

Build brand_line by concatenating "1. ", the brand, the literal " (", str(rating), and ")". A number must go through str() before it can be joined to text.

product_line + "\n" + brand_line joins both lines into one string.

product = "Laptop"
brand = "TechPro"
rating = 4

product_line = product
brand_line = "1. " + brand + " (" + str(rating) + ")"
output = product_line + "\n" + brand_line

STEP 1 OF 3
    Ctrl + Enter to check

    Top K Brands V1 in Python

    Keep going with PythonAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free