Error showing result

0
  

Develop an application that allows you to enter the number of workers needed   for an urban work. In addition, you must ask for the salary that those workers will receive.   Once entered these data, show the total cost in that concept. After   ask for a discount percentage (decimal). Apply this discount to the amount   shown above and show the final amount of the construction.

I have the following problem to solve, but my big doubt that when entering the data and then multiply by the salary:

sueldo_total = (sueldo * num_trabajadores,)

But he throws me an error:

  

salary_total = (salary * num_workers,)
  TypeError: can not multiply sequence by non-int of type 'str'

What could I do in that case?

    
asked by jose donoso 02.04.2017 в 21:31
source

2 answers

1

Try changing that part of the code for this:

sueldo_total = (int(sueldo) * int(num_trabajadores))

so you can multiply them since if you used raw_input to enter both the salary and the number of workers, these will be strings and you can not multiply strings.

    
answered by 03.04.2017 в 23:11
1

The error simply indicates that you are trying to multiply two data of type str (text strings). Your data sueldo and num_trabajadores must be integers ( int ) or decimals ( float ) if the salary is not an integer number.

You just have to do the casting properly:

sueldo_total = float(sueldo) * int(num_trabajadores)

What surely happens is that you are taking the data through console entries. As I showed you in a comment to your question, both raw_input in Python 2.x and input in Python 3.x return a string ( str ). You can do the casting in the same line of input / raw_input :

sueldo = float(input('Ingrese el sueldo por trabajador: '))
num_trabajadores= int(input('Ingrese el numero de trabajadores: '))
sueldo_total = sueldo * num_trabajadores
    
answered by 04.04.2017 в 16:41