Python Forum
I'm getting syntax error while using input function in def.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I'm getting syntax error while using input function in def.
#1
Star 
Please tell me what is wrong and why it is wrong? what is wrong with indentation? please explain
Error when input() is given below def():

   
def details(name,age,address):
    name=input("Enter your name\n")
    age=input('enter age\n')
    address=input('Enter address\n')
    print(f'Hello: {name}')
    print(f'So you are {age} old')
    print(f'Your address is {address}')
details(name,age,address)

TypeError: details() missing 3 required positional arguments: 'name', 'age', and 'address' 
 For above code if parameters are not given the code works
def details():
    name=input("Enter your name\n")
    age=input('enter age\n')
    address=input('Enter address\n')
    print(f'Hello: {name}')
    print(f'So you are {age} old')
    print(f'Your address is {address}')
details()

O/P
Hello: 22
So you are 22 old
Your address is 22
If parameters are given this indentation works
def details(name,age,address):
    print(f'Hello: {name}')
    print(f'So you are {age} old')
    print(f'Your address is {address}')
name=input("Enter your name\n")
age=input('enter age\n')
address=input('Enter address\n')
details(name,age,address)

O/P
Hello: 22
So you are 22 old
Your address is 22
   
Larz60+ write Oct-06-2021, 10:31 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please avoid using images for code.
Reply
#2
You have args in your function but none of them are set.
def (name, age, address):
None of these are set.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Input function oldschool 1 710 Sep-14-2024, 01:02 PM
Last Post: deanhystad
  POST Syntax error amplay 0 646 Aug-07-2024, 02:43 PM
Last Post: amplay
  Input error correction. shakoun 4 1,558 Jun-07-2024, 12:59 PM
Last Post: menator01
  is this really a syntax error? Skaperen 4 1,606 May-25-2024, 07:31 AM
Last Post: snippsat
  World Clock syntax error OscarBoots 1 1,100 May-03-2024, 05:20 AM
Last Post: snippsat
  difference between forms of input a list to function akbarza 6 2,345 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  Syntax error for "root = Tk()" dlwaddel 15 6,396 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 1,295 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 4,905 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 3,000 Jun-19-2023, 03:35 AM
Last Post: 007sonic

Forum Jump:

User Panel Messages

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