This is my attempt at making a calculator for basic equations. Here is a snippet of what I was trying to do on my division side. note, this is the first portion of my code so I'm not sure if it works on any other equation
It only breaks when I type 'quit' right after making an invalid equation.
I've tried to remove the 'pass' from the else and just put the rest of the code in there but it still keeps outputting 'j' (making the computer think it's an invalid equation)
I had it print what it thought I was inputting, it responded with 'j' as what it was outputting. Any chance there's something I'm doing wrong or just the way I typed my code that doesn't bode well with any of the syntax's
def junction():
-def replacings(g):
if g.isdigit():
return float(g)
else:
a = g.split('.')
for i in range(0,len(a)):
if a[i].isdigit():
a = '.'.join(a)
return float(a)
else:
return 'j'
-while True:
equation = input('Please type your equation here. ')
g = equation.split('/')
if equation.lower() == 'quit':
break
else:
pass
if len(g) >= 2:
p = []
for i in range(0,len(g)):
u = replacings(g[i])
if u == 'j':
print('Please try again.!')
junction()
else:
pass
p.append(u)
for e in range(1,len(p)):
f = p[0]/p[e]
p.insert(0,f)
if isinstance(p[0],float) == True:
print(p[0])
else:
break
Aside from the quit portion messing up, it works perfectly fine and runs any equation that includes a single operator. (i.e 10/2 = 5, 9/2 = .333, 10+2/3 = error)
Aucun commentaire:
Enregistrer un commentaire