Search code examples
pythonmultiplication

multiplication function that multiplies given number with 1 to 10


I am trying to write a function that will multiplicate the given number with 1 to 10 and print out the result. Here is my code:

    number = input('Enter a number please: ')
def multiplication(number):
    for i in range(1, 10)
        return print(number =* i)

multiplication(3)

and here is the error:

SyntaxError: invalid syntax erdoganpc@MacBook-Air-Denis pyShit % /Library/Frameworks/Python.framework/Versions/3.8/bin/python3 /Users/erdoganpc/Documents/dev/pyShit/main.py File "/Users/erdoganpc/Documents/dev/pyShit/main.py", line 3 for i in range(1, 10)

can't understand how to solve this problem, please help me :(


Solution

    • Try this
    def multiplication(number):
        result = []
        for i in range(1, 11):
            result.append(str(i) + ' * ' + str(number) + ' = ' + str(number * i))
        return result
    
    • Output:
    ['1 * 4 = 4', '2 * 4 = 8', '3 * 4 = 12', '4 * 4 = 16', '5 * 4 = 20', '6 * 4 = 24', '7 * 4 = 28', '8 * 4 = 32', '9 * 4 = 36', '10 * 4 = 40']