You have to write program to Accept student details Like Name, Marks ( Maths, Chemistry , Physics) and Print Percentage , User will dynamically select number of students ,
For Example :
file.py
input
1 # Number of Users
33 # Physics Marks
44 # Chemistry Marks
77 # Maths Marks
This will output student result All subject's marks and percent must be greater than equal to 35
Constraint
file.py
0 => Marks => 100
Marks must be greater than equal to 0 and less than equal to 100
Passing Criteria:
file.py
Marks >=35 To Pass
Percent >= To Pass
Output (Expected )
Solution
file.py
# define function accept student name, get marks of 3 subjects pcm and calculate percentage
data=[]
n=0
def getData():
n=int(input("Enter Number of Students :"))
for i in range(1,n+1):
user={}
user["Name"]=input("Enter student Name :")
user["Physics"]=checkinput(int(input("Enter Physics Marks :")))
user["Chemistry"]=checkinput(int(input("Enter chemistry Marks :")))
user["Maths"]=checkinput(int(input("Enter math Marks :")))
percentage=((user["Physics"]+user["Chemistry"]+user["Maths"])*100)/300
user["Percent"]=round(float(percentage),2)
user["Result"]=checkResult(user)
addUser(user)
def checkResult(usr):
flag ="PASSES"
if usr["Physics"]<35:
flag="FAILS"
elif usr["Chemistry"]<35:
flag="FAILS"
elif usr["Maths"]<35:
flag="FAILS"
elif usr["Percent"]<35:
flag="FAILS"
return flag
def addUser(usr):
data.append(usr)
print("Data added successfully !!!")
def checkinput(marks):
if marks <= 100 and marks>=0:
return marks
else:
return checkinput(int(input("Please Do not enter Marks More than 100 and Less than 0\nPlease Enter Marks Again : ")))
def printData():
print("_________________________________________________________________________________________________________")
print('{:30s}{:15s}{:15s}{:15s}{:17s}{:19s} '.format("Name","Physics","Chemistry","Maths","Percent[%]","Result"))
print("_________________________________________________________________________________________________________")
for usr in data:
print("\n{:30s}{:5d}{:15d}{:13d}\t\t\t{}\t\t{} ".format(usr["Name"],usr["Physics"],usr["Chemistry"],usr["Maths"],str(usr["Percent"])+"%",usr["Result"]))
print("_________________________________________________________________________________________________________")
getData()
printData()
Output:
file.py
Enter Number of Students :4
Enter student Name :Mahesh Disale
Enter Physics Marks :77
Enter chemistry Marks :87
Enter math Marks :99
Data added successfully !!!
Enter student Name :Nikhil Malvadkr
Enter Physics Marks :66
Enter chemistry Marks :87
Enter math Marks :93
Data added successfully !!!
Enter student Name :Sagar Chavan
Enter Physics Marks :66
Enter chemistry Marks :12
Enter math Marks :99
Data added successfully !!!
Enter student Name :Angad Yadav
Enter Physics Marks :33
Enter chemistry Marks :56
Enter math Marks :98
Data added successfully !!!