# File: extraCredit.py # Author: Dr. Gibson # Date: 2/21/2018 # Section: N/A # E-mail: k.gibson@umbc.edu # Description: # This file contains python code that asks the user for a # grade, checking its validity (dependent on extra credit). ALLOWED = "yes" # input for extra credit being allowed def main(): # set up the boolean flag gradeValid = False # this will evaluate to True as long as the grade is invalid while not gradeValid: # use concatentation to make it one string; use the \ at the # end of each line to allow it to continue to the next line extraC = input("Is extra credit allowed? Enter 'yes' for allowed: ") grade = int(input("What is your score? ")) # grade is between 0 and 100 (inclusive) if grade >= 0 and grade <= 100: gradeValid = True # grade is at least zero, and extra credit is allowed elif grade >= 0 and extraC == ALLOWED: gradeValid = True # if neither of these was true, gradeValid will remain False # and the while loop will run again, asking for new info # exited the while loop, so print out the student's grade print("Congrats on getting a", grade) if extraC == ALLOWED: print("It's cool you're allowed to earn extra credit.") main()