So I have completed a python program which can essentially make a calculator work in real life, i.e. my code will do this:
>>>3*6
>>>18
So, this works very much like a real calculator EXCEPT for the fact that a calculator would print it out on the same line (talking about basic calculator). for example:
>>>3*6= 18
3*6 is input and = 18 is printed by program, and I don't want them in different line. So, if anyone could help me make it on the same line by giving me ideas, it would be appreciated so my calculator would look more pretty. Also, please let me know if my code can be prettier, thanks ;).
OK, here is the pretty messy code:
def addition(a,b):#this will do addition
print (a+b)
def subtraction(a,b):
print(a-b)
def mutiplication(a,b):
print(a*b)
def division(a,b):
print (a/b)
def modulo(a,b):
print(a%b)
def mainoperations(a,b,number, expression):#this will be the place where you will be doing calculations
print("basic calculator: use four operations, +, -, /, *")
indexn=0#the index number starts at 0
while(indexn<len (expression)):#indexn is the index number of the operation you have typed.
if(indexn != '1' or '2' or '3' or '4' or '5' or '6' or '7'or '8' or '9' or '0'):
indexn+=1#this will look at every index of the expression
if(indexn=="+"):#if an addition sign is seen...
addition(expression[:indexn-1],expression[indexn+1:])
elif(indexn=="-"):#if a subtraction sign is seen...
subtraction(expression[:indexn-1],expression[indexn+1:])
elif(indexn=="*"):#if a multiplication sign is seen...
multiplication(expression[:indexn-1],expression[indexn+1:])
elif(indexn=="/"):#if a division sign is seen...
division(expression[:indexn-1],expression[indexn+1:])
elif(indexn=="%"):#if a modulo sign seen...
modulo(expression[:indexn-1],expression[indexn+1:])
expression=input()#the expression is what you inputed
mainoperations#do the function