So I am trying to create a sort of calculator that handles all types of equations. All you have to do is input what you need help on and it will ask you a series of questions based on what equation you need help one, and it will return a value. I am trying to make it so that when a certain string is inputted, it will ask a certain series of questions. However, it asks all the questions regardless of what I input. I'm using Python 3.6.
whichEquation = input("What are you having trouble with? ")
if whichEquation:
"interest"
r = float(input("What is the interest rate?: "))
C = float(input("Deposit cash: "))
t = float(input("For how many years will your deposit be invested?: "))
n = float(input("How many times per year is the interest compounded?: "))
interest = C * (1 + r/n)**(n*t)
print("Your future value is: ",interest,"dollars")
if whichEquation:
"slope"
y1 = float(input("First y point: "))
y2 = float(input("Second y point: "))
x1 = float(input("First X point: "))
x2 = float(input("Second X point: "))
slope = (y2 - y1)/(x2 - x1)
print("The slope is:",slope)
So how would I only show either the 'slope' equation or the 'interest' equation if whichEquation is slope or interest.
if whichEquation: "interest"-> what do you think this code means? The same goes forif whichEquation: "slope".if whichEquation:means 'if whichEquation is truthy, i.e. not an empty string, not zero, etc, then execute the block', so in your case, the block consists of a mere string, and running it does nothing.