Problem with code

Hi, I have a problem with this code:

x = int(input())

if x <= 100:
y = 0.1
else:
y = 0.25

precio = x * (1 - y)
print(precio)

The code seems fine to me, but I’m not expecting the answer that I wanted in the last testcase of the challenge that my teacher sent me. Here are the inputs and expected outputs:

58 = 52.2
7=6.3
200=150
199=149.3

When I display the code with the last input, the answer is 149.25, which is not what im looking for, what should I do?

It looks like you want to round the result up to the nearest tenth.

You can find some info on rounding here:
https://www.freecodecamp.org/news/how-to-round-numbers-up-or-down-in-python/

x = 2.56789

print(round(x, 2))
# 2.57

Hi, I tried that but affects the rest of the expected outputs

the expected outputs all seem rounded to one decimal number, so you should be fine doing that

Hello,

this is a tricky assignment, I like it and I had to dig a bit deeper for the result.

I don’t want to spam you the answer, here’s how you do it:

  • Import math

  • Use math.ceil() on precio

  • for rounding up decimals, you still have to multiply by 10 and divide the result by 10

If you still have issues, come back to us anytime.

2 Likes

That is tricky, didn’t expect round to round 149.25 down to 149.2. I have a small memory of that not working as expected now though.

1 Like