Kami Posted January 27, 2015 Share Posted January 27, 2015 (edited) So I keep trying for my script to ask the user to input a valid number if ones not given or in my case 0-99 It doesn't do this though. the gender.lower() stuff works fine and if I do alien as my input it asks me the question again until I type in either male or female. The only thing I need help with is why my age>=0 and age <=105 isn't working the way its supposed to be Please help! due tomorrow! procrastinated this one big! #ask for age + gender inputage = input ('How old are you? ')gender = input (' male or female? ')#turn age into integerage = int (age)#use while to keep asking for a valid inputwhile age >= 0 and age <= 105 and gender.lower() == 'male' and gender.lower() == 'female' : age = input ('Choose a valid age (0-99) ') age = int (age) gender = input ('male or female? ')if age >= 0 and age <= 5 : print ('Fish')elif age > 6 and age <= 15 and gender.lower() == 'male': print ('Gecko')elif age > 6 and age <= 15 and gender.lower() == 'female': print ('Bunny')elif age > 16 and age <= 30 and gender.lower() == 'male': print ('Snake')elif age > 16 and age <= 30 and gender.lower() == 'female': print ('Parrot')elif age > 30 and age <= 105 and gender.lower() == 'male': print ('Dog')elif age > 30 and age <= 105 and gender.lower() == 'female': print ('Cat') #thank you messageprint()print ('Thanks for using Pet Finder!') Thank you for everyone helping me out! Edit: results How old are you? 55 male or female? maleDogThanks for using Pet Finder! How old are you? 5555 male or female? maleThanks for using Pet Finder! (It's suppose to ask the user for a valid number) Edit2: language =python Edited January 27, 2015 by xgate Link to comment Share on other sites More sharing options...
Dex Posted January 27, 2015 Share Posted January 27, 2015 while age >= 0 and age <= 105 and gender.lower() == 'male' and gender.lower() == 'female' : ^Here you specify that your age has to be from 0 to 105 and the gender has to be male and female. For the while loop to work if you have the wrong age input you'll have to do it like this: while age <= -1 and age >=106 and (gender.lower() == 'male' or gender.lower() == 'female' ): EDIT: this is purely based upon my java knowledge, I've never worked with Python before. So feel free to correct me if I'm wrong. Link to comment Share on other sites More sharing options...
Kami Posted January 27, 2015 Author Share Posted January 27, 2015 (edited) while age >= 0 and age <= 105 and gender.lower() == 'male' and gender.lower() == 'female' : ^Here you specify that your age has to be from 0 to 105 and the gender has to be male and female. For the while loop to work if you have the wrong age input you'll have to do it like this: while age <= -1 and age >=106 and (gender.lower() == 'male' or gender.lower() == 'female' ): EDIT: this is purely based upon my java knowledge, I've never worked with Python before. So feel free to correct me if I'm wrong. Tried this but it didn't ask the user to input a number again if it was over 105 I'm in chat if you want to come there to try and help me edit: Also now doesn't prompt user to input again if gender wasn't male or female Edited January 27, 2015 by xgate Link to comment Share on other sites More sharing options...
Dex Posted January 27, 2015 Share Posted January 27, 2015 Tried this but it didn't ask the user to input a number again if it was over 105 I'm in chat if you want to come there to try and help me while (age <= -1 or age >=106) and (gender.lower() == 'male' or gender.lower() == 'female' ): Sorry my bad, your age obviously can't both be under 0 and over 105, it had to be an 'or' instead of an 'and'. Link to comment Share on other sites More sharing options...
Kami Posted January 27, 2015 Author Share Posted January 27, 2015 Dex fixed my age problem but now gender isn't working correctly Link to comment Share on other sites More sharing options...
Isolate Posted January 27, 2015 Share Posted January 27, 2015 Your code says to only loop whilst male & female... Link to comment Share on other sites More sharing options...
Kami Posted January 27, 2015 Author Share Posted January 27, 2015 Dex solved this for me Great guy while (age <= -1 or age >=106) or(gender.lower() != 'male' and gender.lower() != 'female' ) : age = input ('Choose a valid age (0-105) ') age = int (age) gender = input ('male or female? ')if age >= 0 and age <= 5 : print ('Fish')elif age > 6 and age <= 15 and gender.lower() == 'male': print ('Gecko')elif age > 6 and age <= 15 and gender.lower() == 'female': print ('Bunny')elif age > 16 and age <= 30 and gender.lower() == 'male': print ('Snake')elif age > 16 and age <= 30 and gender.lower() == 'female': print ('Parrot')elif age > 30 and age <= 105 and gender.lower() == 'male': print ('Dog')elif age > 30 and age <= 105 and gender.lower() == 'female': print ('Cat') 1 Link to comment Share on other sites More sharing options...
Dex Posted January 27, 2015 Share Posted January 27, 2015 Dex solved this for me Great guy while (age <= -1 or age >=106) or(gender.lower() != 'male' and gender.lower() != 'female' ) : age = input ('Choose a valid age (0-105) ') age = int (age) gender = input ('male or female? ') if age >= 0 and age <= 5 : print ('Fish') elif age > 6 and age <= 15 and gender.lower() == 'male': print ('Gecko') elif age > 6 and age <= 15 and gender.lower() == 'female': print ('Bunny') elif age > 16 and age <= 30 and gender.lower() == 'male': print ('Snake') elif age > 16 and age <= 30 and gender.lower() == 'female': print ('Parrot') elif age > 30 and age <= 105 and gender.lower() == 'male': print ('Dog') elif age > 30 and age <= 105 and gender.lower() == 'female': print ('Cat') Once again, you're welcome Locked upon request. 1 Link to comment Share on other sites More sharing options...