Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function syntax error
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():
    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():
    for int i in range(0,5):
        x=str(input("enter the name"))
File "", line 19 for int i in range(0,5): ^ SyntaxError: invalid syntax
buran write Mar-07-2021, 06:07 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
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)
Changosoyyo likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

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.

Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a syntax error! rohes_kaugummi 3 326 Jun-23-2021, 05:24 PM
Last Post: deanhystad
  import module with syntax error Skaperen 7 357 Jun-22-2021, 10:38 AM
Last Post: Skaperen
Heart near "(": syntax error Maryan 3 483 Jun-21-2021, 08:05 AM
Last Post: ibreeden
Exclamation getting a syntax error and i don't know why ilikedofs 10 762 May-13-2021, 08:52 PM
Last Post: deanhystad
  Even number code syntax error MrCeez 1 413 May-02-2021, 06:43 PM
Last Post: Larz60+
  error in your SQL syntax Xuli 10 719 May-02-2021, 12:27 PM
Last Post: Xuli
  Syntax error on line 29 manwithjeans 3 613 Feb-27-2021, 08:28 AM
Last Post: perfringo
  Invalid syntax error - need help fixing calgk01 3 661 Feb-23-2021, 08:41 PM
Last Post: nilamo
  Why do I get Syntax error? TechNitium 1 469 Jan-22-2021, 12:49 PM
Last Post: snippsat
  syntax error CompleteNewb 8 768 Jan-08-2021, 04:05 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020