Python Projects

Best Of Four Subjects with Python

PREREQUISITES

To Practice this Program, you should have a basic knowledge of the following Topics:

PYTHON-FUNCTIONSS

INPUT & PRINT FUNCTION

We will use Input & Print Function to collect & print data from the website user into variables.

dt

INTEGER & FLOAT

We will accept the user input in float or integer so that it can be compared.

python-py

COMPARISON OPERATORS

We will use Comparison Operators(< , > etc) to compare for higher marks.

python-py

CONDITIONALS - IF ELIF ELSE

We will use If-Elif-Else to implement the comparisons with Conditions.

WHAT TO DO ?

Ask students for marks in all 5 subjects & tell them the 4 best performed subjects with average marks attained in them.

HOW TO DO ?

Following are the steps to do :

01.

ASK FOR MARKS

At First, We need to ask for marks in all 5 subjects using float data type.

</p>
<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>sub1 = float(input("How much did you score in Subject 1 "))
sub2 = float(input("How much did you score in Subject 2 "))
sub3 = float(input("How much did you score in Subject 3 "))
sub4 = float(input("How much did you score in Subject 4 "))
sub5 = float(input("How much did you score in Subject 5 "))</pre>
</div>
02.

CREATE IF-ELIF-ELSE CONDITIONS

Finally, We will create IF-ELIF-ELSE Conditions assuming one of the subjects performed lowest in each condition.

<div class="wp-block-codemirror-blocks-code-block code-block">
<pre>if sub1<sub2 and sub1<sub3 and sub3<sub4 and sub4<sub5:
  print("SUBJECTS 2, 3, 4 & 5 are the best of four subjects with average %% of " , (sub2+sub3+sub4+sub5)/4)

elif sub2<sub3 and sub2<sub4 and sub2<sub5:
  print("SUBJECTS 1, 3, 4 & 5 are the best of four subjects with average %% of " , (sub1+sub3+sub4+sub5)/4)
  
elif sub3<sub4 and sub3<sub5:
  print("SUBJECTS 1, 2, 4 & 5 are the best of four subjects with average %% of " , (sub1+sub2+sub4+sub5)/4)

elif sub4<sub5:
  print("SUBJECTS 1, 2, 3 & 5 are the best of four subjects with average %% of " , (sub1+sub2+sub3+sub5)/4)
  
else:
  print("SUBJECTS 1, 2, 3 & 4 are the best of four subjects with average %% of " , (sub1+sub2+sub3+sub4)/4)</pre>
</div>
Things We Covered
  • Accepting User Data (Input Function with Float)
  • Comparing for Highest/Lowest numbers (Comparison Operators)
  • Creating IF-ELIF-ELSE (Conditionals)

Posted by Akshay Gupta

Leave a Reply

Your email address will not be published. Required fields are marked *