lichess.org
Donate

Why does my code not work as expected?

number = int(input())
bonus = 0
if number <= 100:
bonus = 5
elif number > 100:
bonus = number * 0.2
elif number > 1000:
bonus = 0.1
bonus_we_get = bonus
our_number_plus_the_bonus = bonus_we_get + number

aditional_bonus = 0
if our_number_plus_the_bonus % 2:
aditional_bonus = 1
edit: im on pycharm python community edition 2023
edit: im on pycharm community edition
elif our_number_plus_the_bonus % 10:
aditional_bonus = 2

total_bonus_we_get = bonus_we_get + aditional_bonus
our_number_plus_the_whole_bonus = total_bonus_we_get + number
print(total_bonus_we_get)
print(our_number_plus_the_whole_bonus)

my output on 15875 in the console is supposed to be 1589.5 17464.5 on two separate lines...
i cant see my mistake pls help
if your "elif number > 100:" triggers, then the following "elif number > 1000:" doesnt trigger.
duno if that solves your problem, but that sure looks like unintended because it means, the "elif number > 1000:" would never trigger. but in general:

please try to post programming problems to a programming forum and/or find a co-programmer you can talk to
and if you post code, do it on pastebin or at least keep the indention,
also when you dont get the desired output it would help if you say what you expect and not only what you get
learn to use a debugger tool
@RonaldoSaisSui

I'll add that usually I'll do a google search and read things like that:

stackoverflow.com/questions/17166074/most-efficient-way-of-making-an-if-elif-elif-else-statement-when-the-else-is-don

Do some tests to confirm I really understand what I read. And then I'll ask on a forum, a co-worker or someone on the internet that knows how to code.

I replied to your post because you proved you did your homework before asking

>edit: im on pycharm python community edition 2023
>edit: im on pycharm community edition
>elif our_number_plus_the_bonus % 10:
>aditional_bonus = 2

>my output on 15875 in the console is supposed to be 1589.5 17464.5 on two separate lines...
>i cant see my mistake pls help
I dont know how to code in pyton (nor any whatsoever) but.

if number <= 100:
bonus = 5
-This is a nested if I suppose, if the previous triggered, is because "number <= 100". Since the number cant be 2 things at the same time, it cant be lower than 100 and higher than 100 at the same time, thus, it the second one wont trigger, just the first one.

elif number > 100:
bonus = number * 0.2

And this if is also nested inside the original one, it wont trigger either, because number is still <= 100, cant be >1000;

elif number > 1000:
bonus = 0.1

You need to add separated ifs. not nested
If number is <= 100, then do this.
if number is >100, then do this. (probably need to say if number is > 100 and <1000) so only this one triggers in case you have 1000 or more, because 1000 is >100, thus this and next statements are both true. Hence, both will trigger.
if number is >1000, then do this.

Probably there is a more elegant way to solve it, but you do need an if statement alone if number is lower or equal than 100, and another different and separated if, if the value is at least 100+

This doesnt mean that you will get the result you expect, as i have not checked the math, but it will solve the logic problem you have there. Just is matter of doing the proper math.