Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:28:27+00:00 2026-06-13T22:28:27+00:00

im teaching myself python and im abit confused #!/usr/bin/python def Age(): age_ = int(input(How

  • 0

im teaching myself python and im abit confused

#!/usr/bin/python

def Age():
        age_ = int(input("How old are you? "))


def Name():
        name_ = raw_input("What is your name? ")


def Sex():
        sex_ = raw_input("Are you a man(1) or a woman(2)? ")
        if sex_ == 1:
                man = 1

        elif sex_ == 2:
                woman = 2

        else:
                print "Please enter 1 for man or 2 for woman "

Age()
Name()
Sex()
print "Your name is " + name_ + " you are " + age_ + " years old and you are a " + sex_ + "."

Error

File “./functions2.py”, line 25, in print “Your name is ” +
name_ + ” you are ” + age_ + ” years old and you are a ” + sex_ + “.”
NameError: name ‘name_’ is not defined

Surely it is defined in the Name() function? Im confused 🙁


Arr I am now thanks for making it a bit more newb proof, Ive now got a problem in the Sex() function. It was returning a number in the print rather than a word “man” or “woman” so I change the code to try fix it. But im getting the following error now File

"./functions2.py", line 16
    2 = woman
SyntaxError: can't assign to literal

I tried to make the 2 an str(2) but it gave me another error. Thanks for you help so far appreciated

#!/usr/bin/python

def Age():
    age_ = raw_input("How old are you? ")
    return age_
def Name():
    name_ = raw_input("What is your name? ")
    return name_
def Sex():
    sex_ = str(raw_input("Are you a man or a woman? "))
    if sex_ == 1:
            1 = man
            return sex_

    elif sex_ == 2:
            2 = woman
            return sex_

    else:
            print "Please enter man or woman "


age_ = Age()
name_ = Name()
sex_ = Sex()


print "Your name is " + name_ + " you are " + age_ + " years old and you are a " + sex_ + "."
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:28:28+00:00Added an answer on June 13, 2026 at 10:28 pm

    It is, but _name‘s scope only extends to the end of the Name() function. Once the Name() function exits, the _name variable is gone.

    Try something like this instead:

    def Name():
        name = raw_input("What is your name? ")
        return name
    
    _name = Name()
    
    print "Your name is " + _name
    

    You’ll need to do something similar for age and sex.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm teaching myself Python 3.2 and I'm trying to make a program to match
I am teaching myself python. I was thinking of small programs, and came up
As part of teaching myself python I've written a script which allows a user
I'm teaching myself Python and I was translating some sample code into this class
I've been teaching myself python and cgi scripting, and I know that your basic
I'm a Python(3.1.2)/emacs(23.2) newbie teaching myself tkinter using the pythonware tutorial found here .
I am teaching myself some Python and I have come across a problem which
I am teaching myself MPI. I am reading Python documentation on reduce and scan:
I'm currently teaching myself python (coming from no programming background, but a lot of
I am teaching myself Python and am running into a strange problem. What I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.