Practice variables, arithmetic, and string concatenation by building a tiny one-item receipt.
You start with:
item = "Coffee Mug"
price = 12
quantity = 3
Build:
Coffee Mug x3 Total: $36
Rules:
- Compute
total = price * quantity. - First line:
"<item> x<quantity>"(e.g."Coffee Mug x3"). - Second line:
"Total: $<total>". - Join the two lines with a newline
"\n"into one stringresult. Just store the text inresult; you do not need to print it.
Wrap each integer with
str(...) before concatenating it with +.
line1 + "\n" + line2 joins both lines into one string.
item = "Coffee Mug"
price = 12
quantity = 3
total = price * quantity
line1 = item + " x" + str(quantity)
line2 = "Total: $" + str(total)
result = line1 + "\n" + line2
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
