Python Forum
Function syntax error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Function syntax error (/thread-32806.html)



Function syntax error - Changosoyyo - Mar-07-2021

Working on this function program and haven't been able to figure out the syntax error. Sure it something simple and its killing me!


#1.value returning function
#FUNCTION 1: A value returning function that asks the user for their favorite number and returns it back to the caller.
def valreturnfn():
    n=int(input("User-enter your favourite number"))
    return n
#2.Non-value returning function
#FUNCTION 2: take the value from FUNCTION 1 and square it and display the result
def nonvalreturnfun():
    n=valreturnfn()
    print("the square of the value returned from funtion1:",n*n)
#3.passing values into a function
#FUNCTION 3: A function that accepts two integers, the 1st argument is the base number, and the 2nd argument is the power to raise the base number to. The function displays the result.
def passvaluesinfn(base,power):
    print("Base raised to the power",base**power)
#4.returning multiple values from a function
#FUNCTION 4: This function asks the user for five first names. The function returns the 5 names back to the caller.
def retmulvales():
    names=[]
    for int i in range(0,5):
        x=str(input("enter the name"))
        x.append(x)
    print(names)
Error:
File "main.py", line 19 for int i in range(0,5): ^ SyntaxError: invalid syntax



RE: Function syntax error - buran - Mar-07-2021

remove int from line 19.

As a side note - input() will return str, so no need to use str() on line 20
Then on line 21 - x.append(x) will raise error. you want names.append(x)


RE: Function syntax error - Changosoyyo - Mar-07-2021

Thank you for both correcting proper tag and assisting. This is my first time posting and using python in general. This is fun! Once again sorry for not posting the tag properly.