Adsense Ad

Thursday 16 May 2019

Python: Dictionary / Tuple / User Input / While Loop. (Mark Sheet Example)

CODE: 

print("Mark sheet Program using dictionary, tuple with while loop \n")
students = {}
bio = ('Student Name','Father Name','Class')
student_counter = 0
exit = False
values = ''
while exit == False:
    student_counter += 1  
    student_details = {}
    for bio_inp in range(0,len(bio)):
        ans = input(bio[bio_inp].title()+": ")
        student_details[bio[bio_inp].title()]=ans.title()
    subList = True
    subjects = {}
    while subList:
        sub = input('Input Subject: ')
        marks = int(input("Input marks obtained out of 100: "))
        if marks < 0 or marks >100:
            print('Invalid Marks given. Must be in 1-100')
            break
        subjects[sub.title()] = marks
        again = input("\nDo you want to enter more subject? [no]: ")
        if again == '' or again.lower() == 'no':
            subList = False
    student_details['Marks'] = subjects
    students['student'+str(student_counter)]=student_details
    ask = input('\nDo you want to input marksheet record? [no]: ')
    if ask == '' or ask.lower() == 'no':
        exit = True
        print('\nData input closed. Run program again\n')
    elif ask.lower() == 'yes':
        continue
    else:
        print('\nInvalid input! Abnormal closed. Run program again\n')
        break
        
for stdkeys,stdval in students.items():
    for std_bio,bio_data in stdval.items():
        totmarks = 0
        sumMarks = 0
        percentage = 0
        if std_bio!='Marks':
            print(std_bio+" "+bio_data)
        else:
            for sub,marks in bio_data.items():
                totmarks = totmarks + 100
                sumMarks = sumMarks + marks
                print('\t'+sub+": "+str(marks))
    percentage = (sumMarks / totmarks) * 100
    print("Total marks obtained: "+str(sumMarks)+" out of "+str(totmarks))
    print("Securing percentage at: "+str(percentage)+"%")
    if percentage >=80 and percentage <=100:
        print("Grade: A+")
    elif percentage >=70 and percentage <=79:
        print("Grade: A")
    elif percentage >=60 and percentage <=69:
        print("Grade: B")
    elif percentage >=50 and percentage <=59:
        print("Grade: C")
    elif percentage >=40 and percentage <=49:
        print("Grade: D")
    else:
        print("Fail")
    print('\n')
print(students)

OUTPUT: 

Mark sheet Program using dictionary, tuple with while loop Student Name: hasan Father Name: JAWAID Class: 1 Input Subject: eng Input marks obtained out of 100: 70 Do you want to enter more subject? [no]: yEs Input Subject: urdu Input marks obtained out of 100: 60 Do you want to enter more subject? [no]: Do you want to input marksheet record? [no]: YES Student Name: ALI\ Father Name: hasan Class: 2 Input Subject: math Input marks obtained out of 100: 99 Do you want to enter more subject? [no]: yes Input Subject: sci Input marks obtained out of 100: 99 Do you want to enter more subject? [no]: Do you want to input marksheet record? [no]: Data input closed. Run program again Student Name Hasan Father Name Jawaid Class 1 Eng: 70 Urdu: 60 Total marks obtained: 130 out of 200 Securing percentage at: 65.0% Grade: B Student Name Ali Father Name Hasan Class 2 Math: 99 Sci: 99 Total marks obtained: 198 out of 200 Securing percentage at: 99.0% Grade: A+

No comments: