Create a gist now

Instantly share code, notes, and snippets.

Evaluating Algebraic expression with Python
#Written by Evan Weinberg
#Welcome to your first session of playing with the Python programming language!
#Today's we will be using it to evaluate expressions for us.
#These lines answer the warm-up questions from today. Use these as examples of how
#to enter calculations in Python.
print "Answers to the Warm-Up Questions:"
print (8*3 - 2*4)
print (27 + 18/9 - 3**2+1)
print (40 + 24)/8 - (2**3+1)
#The lines below set variables x and y. In problems 1 (a),(b), and (c), I started typing
#each expression, but you need to complete them to be the same as the problems from the
#handout.
x = 4
y = -2
print "These are the evaluated expressions for Problem 1."
print (x+y)*1./x
print 3*x
print x
print "Below are the evaluated expressions for Problem 2 that you typed in yourself. "
print "Are they correct? Do they match your hand calculations?"
#Enter your variables and your expressions for 2 (a), (b), and (c) in the space below.
#Remember to print out the values like was done in the program above!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment