how do i input string in the function arg and have this code work?pls Help!!

0 Hasib Ullah · October 15, 2015

def get_gender(gender):
if gender is 'm':
gender = "Male"
elif gender is 'f':
gender = "Female"
print(gender)
get_gender(gender=input("Enter Gender:"))

Post a Reply

Replies

Oldest  Newest  Rating
0 Hasib Ullah · October 16, 2015
sorry!!but this doesn't work.i'm working with Python 3.as far as i know raw_input is for python 2.
it says the "   get_gender(raw_input("Enter Gender:"))

NameError: name 'raw_input' is not defined"
0 sfolje 0 · October 16, 2015
@Hasib Ullah
Your code in aspect of "input-ing string in the function arg" works fine for me (, although i would change cosmetics of the code a little). But what i am worried about is basic nature logic behind the program.

What ur code does:
-When your answer is 'm', it prints out 'Male'
-When your answer is 'f', it prints out 'Female'
-When your answer is anything else, for example '<something else>', program prints out '<something else>'.

If this is what you wanted in the first place, than i dont see the point in your original post.
Else tell us what u want your code to do.
0 Hasib Ullah · October 19, 2015
well.when i run the code it takes the input but it only prints out what i input-ed.for example when i input 'm' it only prints out the 'm' ,why it doesn't print out 'Male'.
+1 sfolje 0 · October 21, 2015
I agree with red
well.when i run the code it works just perfectlly fine. for example when i input 'm' it normaly prints out 'Male'. I again agree with r3d:
a)Try to write code from scratch.
b) Another option: copy-paste your exact code you posted. Maybe you made a little mistake.
0 Hasib Ullah · October 22, 2015
thanks red and sfolje for your help..now i have figured out why my code wasn't working.my code wasn't working because i used "is" instead of "==".replacing "is"with "=="  made the code run..why this happened??is there any difference between "is" and "==" operators...Thanks again
0 Hasib Ullah · October 22, 2015
Thanks ".r3d" you've been very Helpful.You saved me from a massive Headache!!thanks again buddy.
  • 1

Python

107,061 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator