Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function syntax error
#1
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
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.
Reply


Messages In This Thread
Function syntax error - by Changosoyyo - Mar-07-2021, 05:51 PM
RE: Function syntax error - by buran - Mar-07-2021, 06:09 PM
RE: Function syntax error - by Changosoyyo - Mar-07-2021, 10:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,187 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 388 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,607 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,231 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  syntax error question - string mgallotti 5 1,318 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,260 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 896 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  [Solved] unkown (to me) function def parm "name1:name2" syntax. MvGulik 5 1,071 Nov-11-2022, 11:21 AM
Last Post: MvGulik
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,854 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,365 May-18-2022, 06:50 AM
Last Post: ibreeden

Forum Jump:

User Panel Messages

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