CS 115 Summer 2017,

Lab 4 :

Due in Tuesday 6/27/17 in Lab

Educational goals of this lab - verify that every student can do the following:

Verify that every student can use the concepts of:

  • Using differetn structure of if statments.
  • Output operators.
  • typecasts for input of numbers.



  • Problem1: Letter grade
    Write a program to read the grade of of 3 subjects (Physics, Chemistry, and Biology) then calculate the average and show the letter grade according to following conditions:
    Percentage > 90% Grade A
    Percentage > 80% Grade B
    Percentage > 70% Grade C
    Percentage > 60% Grade D
    Percentage > 40% Grade E
    Percentage < 40% Grade F

  • Run Examples
    When you have the program running correctly, Verify that your program produces the same output as in the following test cases.

  • --- Test case 1 ---
    Enter the grade for Physics: 70
    Enter the grade for Chemistry: 80
    Enter the grade for Biology: 90
    
    Your final GPA grade is : B
    
    --- Test case 2 ---
    Enter the grade for Physics: 50
    Enter the grade for Chemistry: 40
    Enter the grade for Biology: 30
    
    Your final GPA grade is : E
    



  • Problem2: max number
    Write a python program to find maximum number between three numbers using if...else. Your program should read three different numbers (assume it will always be the case) from the user and then show the maximum number among these three.
  • Run Examples
    When you have the program running correctly, Verify that your program produces the same output as in the following test cases.

  • --- Test case 1 ---
    Enter first number: 10 
    Enter second number: 50
    Enter third number: 120

    The maximum Number is: 120



  • Problem3: An Auto Insurance Program
    Write a program to determine the cost of an automobile insurance premium, based on driver's age and the number of accidents that the driver has had. The basic insurance charge is $500. There is a surcharge of $100 if the driver is under 25 (<25) and an additional surcharge for accidents as shown in the follwoing table:
    # of accidents Accident Surcharge
    1 50
    2 125
    3 225
    4 or more No insurance

  • Run Examples
    When you have the program running correctly, Verify that your program produces the same output as in the following test cases.

  • --- Test case 1 ---
    
    Enter the age of the driver: 23
    Enter the number of accident: 2
    
    The cost for your insurance is:   725
    
    
    --- Test case 2 ---
    Enter the age of the driver: 26
    Enter the number of accident: 0
    
    The cost for your insurance is:   500
    
    --- Test case 3 ---
    Enter the age of the driver: 27
    Enter the number of accident: 1
    
    The cost for your insurance is:   550
    
    --- Test case 3 ---
    Enter the age of the driver: 23
    Enter the number of accident: 5
    
    no insurance
    



  • Program Prolog
    For every of the the problem above, provide your solution in a file with the comment and prolog provided explaining your information and the program details:
    # supply program prolog
    # Prolog
    # Author:  Mary Smith
    # Email:  Mary.Smith@uky.edu
    # Section: 00
    # Date: 8/31/16
    
    '''
      Purpose: ....
      Preconditions: ....
      Postconditions: ....
    '''
    

  • Requirments:
    1- Choose names for your variables that make sense, dont use short names consist of one letter. Use good, multi-character, meaningful identifiers (variables) names.

    2- Your output should match the run examples provided with the problems above.

    3- Document your work by putting comments at the top of your program, remember that comments in python are either: starts with # in case the comment is one line only or ''' and ''' if the comment is taking more than one line.

    4- At the top of your program, you should have a prolog (name, date, etc.)

    5- Save the solution for problem #1 as grade.py, problem #2 as maximum.py, and problem#3 as insurance.py.

  • When you are done with the three problems, show your three files to the instructor. Then zip the files and submit your work as a submission for Lab 4 on CANVAS.