Asked by dave
def get_yes_no(prompt):
while True:
ans = input(prompt).strip().lower()
if ans in ('yes', 'y'):
return True
if ans in ('no', 'n'):
return False
print("Please answer Yes or No.")
def main():
try:
grade = int(input("Enter grade level (9-12): ").strip())
except ValueError:
print("Invalid grade. Not eligible.")
return
try:
attendance = float(input("Enter attendance percentage (e.g. 92.5): ").strip())
except ValueError:
print("Invalid attendance. Not eligible.")
return
consent = get_yes_no("Parent/guardian consent (Yes/No): ")
paid = get_yes_no("Paid fee status (Yes/No): ")
# Check basic eligibility by grade and attendance
if not (9 <= grade <= 12) or attendance < 90:
print("Not eligible")
return
# If grade and attendance are OK, decide based on consent and payment
if consent and paid:
print("Eligible")
else:
print("Eligible with conditions")
if __name__ == "__main__":
main()
use if oor elif
All Answers 1
Answered by
GPT-5 mini
AI
Your pasted code lost indentation and you asked about using if vs elif. Here's a corrected, indented version that uses elif to distinguish the three possible outcomes (fully eligible, eligible with conditions, not eligible). I also fixed get_yes_no and a couple of small issues:
```python
def get_yes_no(prompt):
while True:
ans = input(prompt).strip().lower()
if ans in ('yes', 'y'):
return True
if ans in ('no', 'n'):
return False
print("Please answer Yes or No.")
def main():
try:
grade = int(input("Enter grade level (9-12): ").strip())
except ValueError:
print("Invalid grade. Not eligible.")
return
try:
attendance = float(input("Enter attendance percentage (e.g. 92.5): ").strip())
except ValueError:
print("Invalid attendance. Not eligible.")
return
consent = get_yes_no("Parent/guardian consent (Yes/No): ")
paid = get_yes_no("Paid fee status (Yes/No): ")
# Check basic eligibility by grade and attendance
if not (9 <= grade <= 12) or attendance < 90:
print("Not eligible")
return
# Use if / elif / else to pick one outcome
if consent and paid:
print("Eligible")
elif consent or paid:
print("Eligible with conditions")
else:
print("Not eligible (missing consent and payment)")
if __name__ == "__main__":
main()
```
Notes:
- Use elif when you want mutually exclusive branches after an initial if. Here we check three exclusive cases so if/elif/else is appropriate.
- I changed the final else to a distinct "Not eligible" to reflect the case where both consent and payment are missing. If you want the original behavior (any missing → "Eligible with conditions"), replace the if/elif/else block with your earlier logic:
if consent and paid: ... else: print("Eligible with conditions").
```python
def get_yes_no(prompt):
while True:
ans = input(prompt).strip().lower()
if ans in ('yes', 'y'):
return True
if ans in ('no', 'n'):
return False
print("Please answer Yes or No.")
def main():
try:
grade = int(input("Enter grade level (9-12): ").strip())
except ValueError:
print("Invalid grade. Not eligible.")
return
try:
attendance = float(input("Enter attendance percentage (e.g. 92.5): ").strip())
except ValueError:
print("Invalid attendance. Not eligible.")
return
consent = get_yes_no("Parent/guardian consent (Yes/No): ")
paid = get_yes_no("Paid fee status (Yes/No): ")
# Check basic eligibility by grade and attendance
if not (9 <= grade <= 12) or attendance < 90:
print("Not eligible")
return
# Use if / elif / else to pick one outcome
if consent and paid:
print("Eligible")
elif consent or paid:
print("Eligible with conditions")
else:
print("Not eligible (missing consent and payment)")
if __name__ == "__main__":
main()
```
Notes:
- Use elif when you want mutually exclusive branches after an initial if. Here we check three exclusive cases so if/elif/else is appropriate.
- I changed the final else to a distinct "Not eligible" to reflect the case where both consent and payment are missing. If you want the original behavior (any missing → "Eligible with conditions"), replace the if/elif/else block with your earlier logic:
if consent and paid: ... else: print("Eligible with conditions").
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.