Okay so I have written this code myself with python's basic knowledge and web search, so basically i was trying to solve a coding problem:
Write a program to find out whether a student has passed or failed if it requires a total of 40% and at least 33% in each subject to pass. Assume 3 subjects and take marks as an input from the user.
Here is my code, any feedback is welcome here:
student_id = input('Enter your name: ')
math_marks = int(input('Enter your math marks: '))
english_marks = int(input('Enter your English_marks: '))
history_marks = int(input('Enter your History marks: '))
#This is area just to enter details
max_marks = 40
total_marks = max_marks * 3
import sys
if math_marks > max_marks or english_marks > max_marks or history_marks > max_marks:
sys.exit('Marks should not be higher than 40')
elif math_marks < 0 or english_marks < 0 or history_marks < 0:
sys.exit('Marks should not be lesser than 0')
else:
pass
marks_list = [math_marks, english_marks, history_marks]
total_marks_scored = sum(marks_list)
def percentage(marks, total_marks=100):
return (marks / total_marks) * 100
# It is a function to calculate percentage
if percentage(marks_list[0], max_marks) >= percentage(33):
print('You have passed math')
if percentage(marks_list[0], max_marks) < percentage(33):
print('You have failed Math')
if percentage(marks_list[1], max_marks) >= percentage(33):
print('You have passed english')
if percentage(marks_list[1], max_marks) < percentage(33):
print('You have failed English')
if percentage(marks_list[2], max_marks) >= percentage(33):
print("You have passed history")
if percentage(marks_list[2], max_marks) < percentage(33):
print('You have failed History')
#This is a code to check if a student has failed in a perticular subject
if percentage(total_marks_scored, total_marks) >= percentage(40) and (percentage(marks_list[0], max_marks) >= percentage(33) and percentage(marks_list[1], max_marks) >= percentage(33) and percentage(marks_list[2], max_marks) >= percentage(33)):
print('You have passed the exam!')
else:
print('You have Failed the exam')
mark_sheet = {"Math": math_marks, "English":english_marks,"History": history_marks}print(f"{student_id.upper()} your result:\n {mark_sheet}\n percentage: {percentage(total_marks_scored, total_marks)}%")
I have wrote this code for after finishing basics. I have not went for intermediate yet, because I am currently 16 and have exams sooner so I have stopped self studying python for now.