is there a way to simplify the code for commission below?
money2 = int(input("how much to withdraw? "))
commission = max(min(round(money2*(10/100)),100),50)
print("the commission is {0}".format(commission))
the former code was used with if. python(or pylint maybe?) adviced me to use min and max. I think it was because this code is included in a function with if itself (the whole code is in the bottom)
money2 = int(input("how much to withdraw? "))
commission = round(money2*(10/100))
if commission > 100:
commission = 100
elif commission < 50:
commission = 50
print("the commission is {0}".format(commission))
the first code is short but not quite quick to read, and the second(or the former) is using too much lines.
is there a way to simplify it? I just want the value of commission to always be at least 50, and 100 at max.
ps. below is the whole code i'm practicing on. My intention was to create a loop of deposit() and withdraw() untill the balance runs out, and if i input more than what i can withdraw, it will ask me again how much to withdraw (so a loop in a loop). My original question is in line 10. Perhaps you could give me other advice for simplifying other parts of this code too. Thanks
def deposit():
money = int(input("how much to deposit? "))
print("{0} has been depostied. total {1}"\
.format(money, balance + money))
return balance + money;
def withdraw():
while True:
money2 = int(input("how much to withdraw? "))
commission = max(min(round(money2*(10/100)), 100),50)
if money2 + commission > balance:
print("not enough balance. total {0}".format(balance))
elif money2 + commission <= balance:
break
print("{0} has been withdraw.".format(money2))
print("{0} is the commission. total {1}".\
format(commission, balance - commission - money2))
return balance - commission - money2
balance = int(input("how much to start with? "))
while True:
balance = deposit()
balance = withdraw()
if balance == 0:
break