Reputation: 13
My program is supposed to answer equations in the form ax = b
a = input("What is the part with the variable? ")
b = input("What is the answer? ")
print('the equation is', a , '=', b)
letter = a[-1]
number = a[0:-1]
answer = b /= number
print(letter,"=",answer)
In line 6, I'm getting an invalid syntax error. How can do it to answer the equation?
Upvotes: 1
Views: 47
Reputation: 1710
This is a better version of you code :
a = input("What is the part with the variable? ")
b = input("What is the left hand side of the equation? ")
print('the equation is {}x = {}'.format(a , b))
answer = float(b) /float(a) // convert the inputs to floats so it can accept mathematical operations
print("x=",answer)
Upvotes: 0
Reputation: 121
a = input("What is the part with the variable? ")
b = input("What is the answer? ")
print('the equation is', a , '=', b)
letter = a[-1]
number = a[0:-1]
answer =float(b)/float(number)
print(letter,"=",answer)
What is the part with the variable? 25c
What is the answer? 8
the equation is 25c = 8
c = 0.32
Upvotes: 1
Reputation: 420
A quick solution. Note, you need to change the type of your input from string (I used float for this, but integer should also work).
a = float(input("What is the part with the variable? "))
b = float(input("What is the answer? "))
print('the equation is',a,'* X =',b)
# solve the equation: aX = b for X
x = b/a
print("X =",x)
Upvotes: 1