Posts

Showing posts with the label Python

Calculator v2.0 - python

Image
Target : Add History Option and make more Accurate In this case I was trying to add a option which can remember past operations and return them when we want with full details ;such as our inputs, operation we done and result. first of all I recoded option called "RESET" which we can rest our calculations rest our process as we can reset our process either after we select the operation and either while we entered onr number also. i used a while loop and  add all the operators in to it as only run program while return is true, then coded for "terminate " option and "reset option" cause some times we maybe have to reset all in this stage too.   def select_op ( choice ):   if ( choice == '#' ):     return - 1   elif ( choice == '$' ):     return 0 and when return -1 for choice its terminating and exiting from program if ( select_op ( choice ) == - 1 ):     #program ends here     print ( "Done. Terminating" )     ex...

Calculator From Python

 Task : make calculator using simple functions in python in build Course Level Programming Assignment - Programming a Calculator using Python In this assignment you will write a computer program from scratch using the Python programming language. This program will function as a simple calculator. Objectives Write a simple Python program that performs arithmetic operations based on the user input Stage 1: A simple calculator Your calculator should provide the following arithmetic and control operations. Arithmetic Operations Addition (+)                  add(a,b) Subtraction (-)              subtract(a,b) Multiplication (*)          multiply(a,b) Division (/)                   divide(a,b) Power (^)    ...

Advance Functions In Python

Image
  Loops and Iterations Iteration is the repeated execution of the same block of code.  Why do we need Loops and Iterations ? Why do we repeat? Let’s say that we want to enter marks for a student and check to see if the student has passed the exam by getting more than 50 marks. We would write one line of code for one student. Now let’s say thea we have 5 students and we want to do the same. One way of doing this is to copy the code written for one student 5 times.  Is this the best way of doing this? If we had a way of writing the code once yet repeat it 5 times. it would be easier to write and if necessary, change languages allow us a way to repeatedly execute code multiple times.   We already know how to write code that goes in a sequence. We also we know how to write code to check some condition and decide which way to go usingif-else and switch- case in python. We can also repeat or iterate as shown in the diagram. Let's look at how this works. We have 5 grades in...