-1

I'm trying to write a calculator for a project in class but keep getting hit with an error:

Traceback (most recent call last): File "C:\Users\shane\PythonPrograms\louie.py", line 56, in tax_percent = (price * tax) TypeError: can't multiply sequence by non-int of type 'float'

My code is below. Can anyone help me debug this?

size_types = {'mini',
              'regular',
              'large'
}

meat_types = {'pork',
              'beef',
              'chicken'
}

def price_pork_meal(size):
    if size == 'mini':
        return 3.00
    if size == 'regurlar':
        return 4.00
    if size == 'large':
        return 6.00
    else:
        return (input('Please try again:'))
    return size

def price_beef_meal(size):
    if size == 'mini':
        return 4.00
    if size == 'regular':
        return 7.00
    if size == 'large':
        return 9.00
    else:
        return (input('Please try again:'))
    return size

def price_chicken_meal(size):
    if size == 'mini':
        return 3.50
    if size == 'regular':
        return 6.00
    if size == 'large':
        return 8.00
    else:
        return (input('Please try again:'))
    return size

def final_price(price, tax_percent):
    price = size
    total_price = price + tax_percent
    return total_price


size = (input('Please enter mini, regular, or large:\n'))

price = size

tax = 0.825

tax_percent = (price * tax)

print(final_price(price, tax_percent))
River
  • 8,585
  • 14
  • 54
  • 67
  • Please put your full code in your question – River Mar 07 '17 at 02:51
  • Seems like the variable `price` is a `list` or a `tuple` and you are trying to multiply it by a `float`. – Abdou Mar 07 '17 at 02:54
  • There are many problems in this code. None of the functions or the initial dictionaries ever get used at all. @Abdou in fact it is a string; the parentheses around `(input('Please enter mini, regular, or large:\n'))` have no effect. – Karl Knechtel Oct 23 '22 at 03:18

1 Answers1

0

Your approach is not valid in python. You can't multiply a sequence with a floating-point value, as written in the error.

This won't work:

a = (1,2,3)
b = a * 0.25

You can use numpy, which supports this (and much much more) or implement this yourself like:

a = (1,2,3)
b = list(map(lambda x: x*0.2, a))  # or many other approaches; outer list needed in python3 to make it a list instead of an generator-expression
sascha
  • 32,238
  • 6
  • 68
  • 110
  • This answer is misleading; the value in OP's code being multiplied (unsuccessfully) is in fact a *string* (which, yes, is also a sequence). – Karl Knechtel Oct 23 '22 at 03:19