Product


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/3?curriculum_id=4f89dab3d788890003000096#


The code looks right and submitted, but after I tried to add a user input to test it out, it no longer works

Traceback (most recent call last):
File "python", line 8, in
File "python", line 4, in product
TypeError: can't multiply sequence by non-int of type 'unicode'


def product (integers):
    mult = 1
    for i in integers:
        mult *= i
    return mult
    
integers = raw_input("Enter some numbers:")
product(integers)


#2

Hi @huangela ,

The raw_input function returns the user's input as a string. If the integers are entered as a series of numbers separated by spaces, you need to split up the string, and convert the contiguous series of digits to ints. Pass a list of the ints to the product function and print the value that it returns.

See Python: str.split.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.