'build a calculator for python 3

hey everyone I need your help for my programming course, I am pursuing my undergraduate degree in psychology. The question is: The python application you will develop will receive the mathematical operation that the user wants to calculate and print the result on the screen. This process will continue until the user enter "Done". The application will terminate when the user enters the end. Conditions and restructions: 1)you will operate with positive integers 2)only 4 operations will be used 3)remember the priority of the operation 4)you will use "*" as a cross 5)no brackets will be used 6)it is forbiddento use an external module 7)you are not responsible for the user's incorrect entries 8)bulit-in functions you can only use the following: int float range print input len str max min

you can use all functions of list and str data structure.



Solution 1:[1]

there are some things to be considered:

  1. since you write, no modules are allowed, I assume, this should only run in the CLI. This will make the exercise incredibly easier, since GUI and Python are a Love-Hate-Realionship of its own.

  2. Assuming I understood your assign right, the user will type a list of expressions like "1*2+3/4-5" for example, typing "Done" will indicate, that these should processed and the result should be printed, right? If the User types end, the script will stop working.

  3. Also, you will only have to handle positives, this also, and the fact that you don't have to validate the user entries, makes it very easy. I won't give you a full solution, since you should learn something with this assignment, but here are some hints, that may nudge you in the right direction.

Hints:

  • The input will be in a string, so handling strings will be a main task. You should look up the documentation to know, in what ways you can manipulate strings. Also have a closer look at helper functions like split, if you have the word Done more than one time in the string.
  • Strings are in fact just lists of letters, punctuation and numbers.
  • Since strings are just a list, you won't have a neatly stored 22 in there, it will be a [2][2] surrounded by an operation or the words Done or end. You will have to go through your string, break it up in smaller parts, and then from there on, call functions to do whatever there is to do.
  • Keep in mind, that there are literally millions of ways to achieve what you have to do, if you aren't familiar with programming, keep it simple, break it up in smaller steps and then just proceed through the exercise.

Hope this will help you. If it helped you or gave you a hint in the right direction, I would appreciate an upvote.

Have fun coding.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Phil