+ 1

Kaleidoscopes Challenge: SOLVED

Hey folx, I'm trying to complete the Kaleidoscopes challenge. My code is giving the correct result, but because it's not rounding to two decimal places, I keep failing 3/5 tests. Can anyone help me figure out what's wrong? Challenge: https://www.sololearn.com/coach/44?ref=app My Solution: https://code.sololearn.com/cCq6UOU7k5Z4/?ref=app

27th Feb 2020, 3:01 PM
Élysse Marcellin
Élysse Marcellin - avatar
12 Réponses
+ 4
It should be like this: print(f'{total_cost * disc:.2f}') I recommend you to go through the complete python tutorial, i am sure that this is mentioned there.
27th Feb 2020, 3:50 PM
Lothar
Lothar - avatar
+ 3
If the purchase is 7, the result from your code is 33.705000000000005. So you have to round according the task description (if there is one), or use standard formatting output like f'{YourNumber:.2f}' with f-string.
27th Feb 2020, 3:24 PM
Lothar
Lothar - avatar
+ 2
Thanks Lothar! That formatting tip did the trick. I'm still trying to go through the python course, but I had to go back over some content to better understand it before I moved on again. But thanks for the help!
27th Feb 2020, 4:23 PM
Élysse Marcellin
Élysse Marcellin - avatar
+ 2
Wow, this makes zero sense to me and seems overly complicated for it's level. If the discount is 10% why are you using 0.09 and the Tax is 7%. Wouldn't the numbers be .10 for the discount and .07% for the tax.
31st Jan 2023, 6:29 AM
TheKyMethod
TheKyMethod - avatar
+ 1
Lothar the task says the result should be rounded "to 2 decimal places", but I realised I don't know how to do that. I tried using the "round" function, but then I wasnt sure how to get the two decimal places using that either. How would I use the f-string function in this case?
27th Feb 2020, 3:33 PM
Élysse Marcellin
Élysse Marcellin - avatar
+ 1
print(round(yourdescription,2))
12th Jul 2021, 7:38 PM
Lee 4 Code
Lee 4 Code - avatar
+ 1
Gkidan can you please explain the print statements… t,2 And the else print statement?
2nd Aug 2022, 5:41 PM
M Heather Fleming
M Heather Fleming - avatar
+ 1
Round the value of t to 2 decimal place
2nd Aug 2022, 5:52 PM
Gkidan
Gkidan - avatar
0
kalscp = 5.00 tax = 1.07 disc = 0.90 purchase = int(input()) total_cost = (purchase * kalscp) * tax t=total_cost*disc if purchase>1: print(round(t,2)) else: print(round(total_cost,2))
30th Jul 2022, 4:34 PM
Gkidan
Gkidan - avatar
0
kalscp = 5.00 tax = 1.07 disc = 0.90 purchase = int(input()) total_cost = (purchase * kalscp) * tax t=total_cost*disc if purchase>1: print(round(t,2)) else: print(round(total_cost,2))
31st Jan 2023, 6:36 AM
Gkidan
Gkidan - avatar
0
kscopeQ = int(input()) kscopeCost = 5 kscopeTotal = kscopeCost * kscopeQ tax = kscopeTotal * 0.07 if kscopeQ>1: discount = kscopeTotal * .10 kscopeWD = kscopeTotal - discount kscopeWD += tax print (kscopeWD) elif kscopeQ<2: kscopeTotal += tax print (kscopeTotal) This is my sesame street version. I keep getting the discounts scenarios wrong. Like if the input is 3 the answer is 14.45, yet I'm. Always off by 10 and I'll get 14.55 yet I checked the math in a calculator and I be getting 14.45. I'm thinking I have something in the wrong place and I can't see it. Need extra eyes.
31st Jan 2023, 7:21 AM
TheKyMethod
TheKyMethod - avatar
0
TheKyMethod I'm getting the same, did you managed to fix your code?
2nd Mar 2023, 9:16 AM
Camelia
Camelia - avatar