Two brands sell the same product. Show the one with the higher rating.
You start with:
brand1 = "TechPro"
rating1 = 4
brand2 = "MegaCorp"
rating2 = 5
Build:
1. MegaCorp (5)
Rules:
- Use
if/elseto pick the winner:brand1whenrating1 > rating2, otherwisebrand2. - Store the winner's name and rating in
best_brandandbest_rating. - Format the result as
"1. Brand (rating)"and store it inoutput.
Pick the winner into
best_brand and best_rating first, then build the output text from them.
In Python a number must go through
str() before it can be joined to text.
brand1 = "TechPro"
rating1 = 4
brand2 = "MegaCorp"
rating2 = 5
if rating1 > rating2:
best_brand = brand1
best_rating = rating1
else:
best_brand = brand2
best_rating = rating2
output = "1. " + best_brand + " (" + str(best_rating) + ")"
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
