CS 115 Summer 2017,

Lab 6 :

Due in Thursday 7/13/17 in Lab

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

  • Verify that every student can define simple functions.
  • Use loop (for, while) .
  • Using differetn structure of if statments.
  • Output operators.
  • typecasts for input of numbers.



    Overview:

    A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. As you already know, Python gives you many built-in functions like print(), etc. but you can also create your own functions. In this lab, we will build different simple functions that togehter will make a simple Calculator.







  • Make a Simple Calculator In this program, we ask the user to choose the desired operation. Options 1,2,3 and 4 are valid where option 5 to get out from the program. If the user select one of the options in 1-4 Two numbers are taken and an if...elif...else branching is used to execute a particular section. We need to build every operation in a User-defined function add() for option 1, subtract() for option 2, multiply() for option 3 and divide() for option 4. Once the user select one of the operation we supposed to show the result for the input values and then show the Menu again until the user choose to Quit. In case the user enter invalid option (e.g. 6) the program should show the user a message ("Invalid input") and show him the Menu again to enter a valid option. Please look at the three test cases and if you have any question ask me before you start.
  • 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 ---
    	Please choose from the menu.
    	============================
    	1.Add
    	2.Subtract
    	3.Multiply
    	4.Divide
    	5.Quit
    	============================
    	Enter your Choice: 1
    	Enter first number: 5
    	Enter second number: 10
    	5 + 10 = 15
    	Please choose from the menu.
    	============================
    	1.Add
    	2.Subtract
    	3.Multiply
    	4.Divide
    	5.Quit
    	============================
    	Enter your Choice: 5
    	*****Good Bye*****
    
    --- Test case 2 ---
    	Please choose from the menu.
    	============================
    	1.Add
    	2.Subtract
    	3.Multiply
    	4.Divide
    	5.Quit
    	============================
    	Enter your Choice: 4
    	Enter first number: 3
    	Enter second number: 4
    	3 / 4 = 0.75
    	Please choose from the menu.
    	============================
    	1.Add
    	2.Subtract
    	3.Multiply
    	4.Divide
    	5.Quit
    	============================
    	Enter your Choice: 2
    	Enter first number: 5
    	Enter second number: 3
    	5 - 3 = 2
    	Please choose from the menu.
    	============================
    	1.Add
    	2.Subtract
    	3.Multiply
    	4.Divide
    	5.Quit
    	============================
    	Enter your Choice: 5
    	*****Good Bye*****
    
    --- Test case 3 ---
    	Please choose from the menu.
    	============================
    	1.Add
    	2.Subtract
    	3.Multiply
    	4.Divide
    	5.Quit
    	============================
    	Enter your Choice: 6
    	Invalid input
    	Please choose from the menu.
    	============================
    	1.Add
    	2.Subtract
    	3.Multiply
    	4.Divide
    	5.Quit
    	============================
    	Enter your Choice: 
    
    
  • 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/17 ''' Purpose: .... Preconditions: .... Postconditions: .... '''
  • Requirments:
    1- You have to build four different functions (add(), subtract(), multiply(), divide()) also you need to have the main function that will have the Menu and the other things.
    2- Choose names for your variables that make sense, do not 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 this lab in a file (calculator.py).
  • When you are done with the lab, show your file to the instructor, sign the lab sheet, and then submit your solution on CANVAS under lab6.