PREREQUISITES
To Practice this Program, you should have a basic knowledge of the following Topics:
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 :
</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>
<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
