Review--i.e. You Should Know This Stuff Because We're Going to Use These Ideas Quite a Bit.
It's time to dust out those cobwebs. Let's start by building a basic calculator program. This program should bring to mind things we learned together in Intro to Programming--it doesn't require anything new from you.
Through this module, you should demonstrate that you understand how to:
1) define and use variables 2) define and call functions 3) prompt the user for information 4) use if-statements 5) pass arguments into functions 6) COMMENT YOUR CODE! |
Directions:
1) Start a new module and use our normal file-naming convention: Calculator_YourLastName_YourFirstName.
2) This calculator program should ask the user what operation they would like to perform, ask them for two numbers and then print the result.
3) Each operation should be its own function.
If you want to set out the basic structure of your program without having to go into the details of each function right away, you can write "pass" in the body of the function.
i.e. def function():
pass
If you want to set out the basic structure of your program without having to go into the details of each function right away, you can write "pass" in the body of the function.
i.e. def function():
pass
4) If the user enters values which will not work for either the choice given or the operation performed, I want your program to prompt the user for appropriate choices.
5) #COMMENT THE LIVING DAYLIGHTS OUT OF THIS PROGRAM.
One of the major advantages of using Python is its readability. Commenting helps improve the readability of code. If you're not commenting, it kind of defeats the purpose of using Python.
One of the major advantages of using Python is its readability. Commenting helps improve the readability of code. If you're not commenting, it kind of defeats the purpose of using Python.
6) Rewrite your program so that the numbers the user chooses are passed as arguments into the operation functions.