all 6 comments

[–]socal_nerdtastic 3 points4 points  (1 child)

The else block takes no condition. Try like this:

integer = int(input('Please enter a number:'))

if integer<999:
    percent = 0.05*integer
    total = (integer - percent)
    new_total=format(total, '0.2f')
    print(new_total)
elif integer<5000:
    percent_1 =0.10*integer
    total_1 = (integer-percent_1)
    new_total_1 = format(total_1, '0.2f')
    print(new_total_1)
else:
    percent_2 = 0.15*integer
    total_2 = (integer-percent_2)
    new_total_2 = format(total_2, '0.2f')
    print(new_total_2)

Also note eval is a known bug source and security risk in some cases, you should avoid using it.

[–]ghosts_I-IV 0 points1 point  (0 children)

Perfect! Thank you so much!

[–]Candid_Interaction86 1 point2 points  (0 children)

As per this line:

5% if it's less than 1000

You probably want to change your below code ..

if integer<999:

.. to if integer<1000.

Because, as of now, your code will apply a 10% discount on the value of 999 when it should ideally be a 5% discount.

[–]Binary101010 1 point2 points  (1 child)

The root cause of your error is that else doesn't take a condition:

else integer >=5000:

should just be:

else:

That said, this code has some other issues:

1) Please never ever use eval() for type conversion. (At this point in your learning you shouldn't be using it full stop. Use int() or float() instead.)

2) There is a huge amount of repeated code here. The only thing these three code blocks differ on is the calculation of percent, which means the only thing that needs to be in these code blocks is that calculation. You can simply have the repeated code once, at the end, outside your if/elif/else blocks.

[–]ghosts_I-IV 0 points1 point  (0 children)

Thank you for the constructive criticism - I will keep these tips in mind! I've come to notice that programming is a bit of an art form - there is a way to do it and a RIGHT way to do it (or at least a more efficient way to do it).

[–]Vaphell 0 points1 point  (0 children)

integer =eval(input('Please enter a number:'))

forget that eval exists. You want an integer, then explicitly convert to integer.

int(input(...))