First, the "function" (which is a class) float
does not read the program input. That is, you cannot ask the user a value through it, for this you will need the function input
(raw_input
in Python 2). Use float
only to define a numerical value from the read value. We can add to the process a validation to ensure that the reported salary is less than or equal to 700, as stated in the statement:
while True:
try:
salario = float(input('Informe o salário: R$ '))
if not 0 < salario <= 700.00:
raise ValueError('Salario precisa positivo e até 700')
break
except ValueError as error:
print(error)
Thus the user will be asked until he enters a valid value:
>>> Informe o salário: R$ a
could not convert string to float: 'a'
>>> Informe o salário: R$ 800
Salario precisa positivo e até 700
>>> Informe o salário: R$ 500
We do the same for the value sold, but now without the validation of the range:
while True:
try:
vendas = float(input('Informe o valor em vendas: R$ '))
break
except ValueError as error:
print(error)
Statement says there is a 4.5% bonus on the sale value:
bonificacao = 4.5 / 100
Plus a 1.2% increase if sales exceed 15,000:
if vendas > 15_000:
bonificacao += 1.2 / 100
Therefore the final amount of the salary will be:
final = salario + vendas * bonificacao
I made more lines, update the page. Now I wonder if it’s all in the same condition.
– user143390