Need help ASAP - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Need help ASAP (/thread-5066.html) |
Need help ASAP - ralfi - Sep-17-2017 Need help with this code, why does it have the error??????? gender =(input("What is your gender?")) f= "female" m="male" Age = float(input("What is your age?")) type= float History =(input("Does your patient have family history of breast cancer?")) T= "true" F= "false" if int > 40 and f: print('Consider ordering mammogram') elif int < 40 and f and T: print('Consider mammogram because of family history') else: print('No mammogram order reccommended') What is your gender?f What is your age?41 Does your patient have family history of breast cancer?T Traceback (most recent call last): File "<ipython-input-9-412bedcea11e>", line 9, in <module> if int > 40 and f: TypeError: '>' not supported between instances of 'type' and 'int' RE: Need help ASAP - ichabod801 - Sep-17-2017 You are getting that error because you are misusing Python keywords (type, float, and int). int is a type of data (the integer type), it's not a value you can test against instances of integers (like 40). Also your code is completely messed up. You ask the gender, and put the response in the gender variable. You then put the text 'female' in the f variable. These variables have no connection to each other. So when you test just f, all you are doing is testing to see if there is anything in that string. And there is, the text 'female'. So it has no relation to the question you asked. You want to test something like gender == 'f' , because gender is where the response is, and 'f' is what you're looking for.
RE: Need help ASAP - ralfi - Sep-17-2017 can you fix it and post it again RE: Need help ASAP - ichabod801 - Sep-17-2017 I'll help you fix it, but I won't do it for you. I want you to do three things:
|