asked 9.7k views
4 votes
Create a python program that asks the user to input the subject and mark a student received in 5 subjects. Output the word “Fail” or “Pass” if the mark entered is below the pass mark. The program should also print out how much more is required for the student to have reached the pass mark.

Pass mark = 70%



The output should look like:

Chemistry: 80 : Pass: 0% more required to pass

English: 65 : Fail: 5% more required to pass

Biology: 90 : Pass: 0% more required to pass

Math: 70 : Pass: 0% more required to pass

IT: 60 : Fail: 10% more required to pass

1 Answer

1 vote

HERE IS THE CODE

  • pass_mark = 70
  • # Input marks for each subject
  • chemistry_mark = int(input("Chemistry: "))
  • english_mark = int(input("English: "))
  • biology_mark = int(input("Biology: "))
  • math_mark = int(input("Math: "))
  • it_mark = int(input("IT: "))
  • # Calculate pass or fail status and percentage required to pass
  • chemistry_status = "Pass" if chemistry_mark >= pass_mark else "Fail"
  • chemistry_percent = max(0, pass_mark - chemistry_mark)
  • english_status = "Pass" if english_mark >= pass_mark else "Fail"
  • english_percent = max(0, pass_mark - english_mark)
  • biology_status = "Pass" if biology_mark >= pass_mark else "Fail"
  • biology_percent = max(0, pass_mark - biology_mark)
  • math_status = "Pass" if math_mark >= pass_mark else "Fail"
  • math_percent = max(0, pass_mark - math_mark)
  • it_status = "Pass" if it_mark >= pass_mark else "Fail"
  • it_percent = max(0, pass_mark - it_mark)
  • # Output results
  • print(f"Chemistry: {chemistry_mark} : {chemistry_status}: {chemistry_percent}% more required to pass")
  • print(f"English: {english_mark} : {english_status}: {english_percent}% more required to pass")
  • print(f"Biology: {biology_mark} : {biology_status}: {biology_percent}% more required to pass")
  • print(f"Math: {math_mark} : {math_status}: {math_percent}% more required to pass")
  • print(f"IT: {it_mark} : {it_status}: {it_percent}% more required to pass")

The program asks the user to enter their scores for each subject, determines if they passed or failed, and calculates how much more they need to score in order to pass. The percentage needed to pass is never negative thanks to the use of the max() method. The desired format for the results is printed using the f-string format.

answered
User Sinoroc
by
8.7k points

No related questions found