Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: unsupported operand type(s) for +: 'float' and 'tuple' error when trying to add multiple floats together

My functions is:

def process_coins(num_of_pennies, num_of_nickels, num_of_dimes, num_of_quarters):
  total_of_pennies = (float(num_of_pennies) / 100)
  total_of_nickels = ((float(num_of_nickels) * 5) / 100)
  total_of_dimes = (float(num_of_dimes) / 10)
  total_of_quarters = ((float(num_of_quarters) * 0,25))

  total_money_inserted_in_machine =  total_of_pennies + total_of_nickels + total_of_dimes + total_of_quarters
  return total_money_inserted_in_machine

And I am calling my function like this

    num_of_pennies = int(input("How many pennies:"))
    num_of_nickels = int(input("How many nickels:"))
    num_of_dimes = int(input("How many dimes:"))
    num_of_quarters = int(input("How many quarters:"))

    total_money_inserted = process_coins(num_of_pennies, num_of_nickels, num_of_dimes, num_of_quarters)

It is supposed to just add the amounts together and return it so I can use it later but it gives "TypeError: unsupported operand type(s) for +: ‘float’ and ‘tuple’" error can anyone tell me what I am doing wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your problem seems to be using 0,25 when I think you want to use 0.25. In Python, floats use a dot (.) instead of a comma (,). That’s creating a tuple instead of a float.

The error you’re seeing happens exactly because of that:

>>> total_of_quarters = ((float(num_of_quarters) * 0,25))
>>> type(total_of_quarters)
<class 'tuple'>
>>> total_of_quarters
(0.0, 25)

Instead, I think you want to use:

>>> total_of_quarters ((float(num_of_quarters) * 0.25))
>>> type(total_of_quarters)
<class 'float'>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading