Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1)A certain Cs professor gives 100-point exams that the are graded on the scale

ID: 3842439 • Letter: 1

Question

1)A certain Cs professor gives 100-point exams that the are graded on the scale 90-100:A, 80-89:B,70-79:C, 60-69:D,<60:F. Write a program that accepts an exam score as input and use a decision structure to calculate the corresponding grade.
2) write a program that accepts a date in the form monthly/day/year. And output whether or not the date is valid. For example 5/24/1962 is valid, but 9/31/2000 is not.(September has only 30 days) please am trying to code them in python shell... Please use python codes

Explanation / Answer

1)

def main():

n = eval(input("Exam Score:"))

g = ""

if n >= 90:

g = "A"

elif

n >= 80:

g = "B"

elif n >= 70:

g = "C"

elif n >= 60:

g = "D"

else: g = "F"

print("Grade:",g)

main()

2)def leapCheck(year):

    # return 1 if its leap year and zero for normal year.

    if year % 400 == 0:

        return 1

    elif year % 100 == 0:

        return 0

    elif year % 4 ==0:

        return 1

    else:

        return 0

def main():

    print('A program to check valid date.')

    userDate = input('Please enter date in form Month/Day/Year.')

    try:

        # split String into 3 var

        # x.split gets ValueError if no '/'x3

        month,day,year = userDate.split('/')

         

        # convert String to Integer

        # int() gets ValueError if user enter String,Float

        month = int(month)

        day = int(day)

        year = int(year)

         

        # use List to check month

        month31 = [1,3,5,7,8,10,12]

        month30 = [4,6,9,11]

         

        # start check if month is February.

        if month == 2 :

            leapYear = leapCheck(year)

            if leapYear == 1:

                if day <= 29 and day >= 1:

                    print(' Yes its valid date!')

                else:

                    print(' No, its not valid date.')

            if leapYear == 0:

                if day <= 28 and day >= 1:

                    print(' Yes its valid date!')

                else:

                    print(' No, its not valid date.')   

         

        # check for Month31

        for i in month31:

            if i == month:

                if day>=1 and day<=31:

                    print(' Yes its valid date!')

                else:

                    print(' No, its not valid date.')

                 

        # check for Month30

        for i in month30:

            if i == month:

                if day>=1 and day<=30:

                    print(' Yes its valid date!')

                else:

                    print(' No, its not valid date.')       

         

        # in case user input silly month (below 1 or over 12

        if month < 1:

            print(' Please correct date input.')

        if month > 12:

            print(' Please correct date input.')

         

    except ValueError:

        print(' Please correct date input.')

    except:

        print(' Unknow Error!')

     

if __name__ == '__main__':

    main()