Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help ASAP
#1
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'
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
can you fix it and post it again
Reply
#4
I'll help you fix it, but I won't do it for you. I want you to do three things:
  • Read the BBCode link in my signature below. That will show you how to correctly post code on the forums.
  • Eliminate everything before the first if statement except the lines using input. Those are all you need. The rest have no connection, as I explained.
  • Fix the first if statement based on my last post, and post the updated code here.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  kill thread or process asap, even during time.sleep nanok66 4 2,940 Apr-29-2020, 10:13 AM
Last Post: nanok66
  Need help asap lucaaa_s02 1 1,740 Jul-17-2019, 09:15 PM
Last Post: Larz60+
  Having issues getting a loop to work PLESSE HELP ASAP manthus007 1 2,135 Aug-25-2018, 10:44 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020