You can simplify all the input into one for statement using a dictionary.
import sys gradeDict = {'midterm': {'number': 2, 'percent': 1/5}, 'summary paper': {'number': 1, 'percent': 1/10}, 'response paper': {'number': 1, 'percent': 1/5}, 'discussion score': {'number': 10, 'percent': 1/50}, 'top hat scores': {'number': 5, 'percent': 1/50}} def formatNumber(num): formatDict = {'1': 'st', '2': 'nd', '3': 'rd'} lastNum = str(num)[len(str(num))-1:] try: return formatDict[lastNum] except: return 'th' finalGrade = 0 for item, info in gradeDict.items(): for count in range(1, info['number']+1): inputting = True while inputting: try: grade = float(input(f"Enter the grade for your {str(count)+formatNumber(count)+' '+item}: ")) if grade < 0 or grade > 100: print("Incorrect range for the grade") continue finalGrade += grade*info['percent'] inputting = False except: print("Invalid input") percentReference = {86: 'A', 74: 'B', 62: 'C', 54: 'D', 0: 'F'} for percent, grade in percentReference.items(): if finalGrade >= percent: print(f"You got a(n) {grade} with an average of {finalGrade}") sys.exit()If you have any questions on any of the code feel free to ask. Hope this helps!