So the question I am trying to write code for is this: A student will not be allowed to sit in exam if his/her attendence is less than 75%. Take following input from user Number of classes held Number of classes attended. And print percentage of class attended Is student is allowed to sit in exam or not. Ask user if he/she has medical cause or not ( 'Y' or 'N' ); print accordingly.
Once the user input fails my if condition it is supposed to print a certain message but it just prints something completely different.
I've written an if else statement in case someone hasn't attended 75% of classes. If they haven't the code should ask whether or not they were medically excised. If they were they are allowed to sit the exam but if they responded with anything that isn't a pre-specified "yes" response then they are not allowed to sit the exam. Meaning if they had less than 75% attendence and to the question "are you medically excused" they write "no" or "jk" or "alkdjf" the code should not allow them to sit the exam.
#number of classes held:
total_classes = int(input ("How many clases have been held in the year
thus far? "));
#number of classes attended:
attended_classes = int(input("How many classes have you attended? "));
#percentage of classes
percentage_attendence = ((attended_classes/total_classes)*100);
if percentage_attendence < 75:
medic = input("Do you have a medical cause? (Y/N or y/n only)");
if medic == "y" or "Y" or "yes" or "ye":
print ("You are free to take part in the exam");
else:
print ("You can not take part in the exam");
else:
print ("You are free to take part in the exam");
The problem is that once I've told the computer that I haven't attended 75% classes, no matter what I answer to the medic question the code still prints I'm allowed to take the exam. If I answer yes, I have the certification, it prints I can take the exam but even if I answer with something that isn't a pre-defined yes in the code python still allows me to take the exam...