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_ + "."