# notes sent to me from a student because I accidentially forgot to save mine... oops! #!/usr/bin/env python # coding: utf-8 # In[25]: # Section 2.7 Calculations # Math Operators # + is addition # - is subraction print(3+5) print(5-3) # * is used for multiplication # / is for division print(3*5) print(15/2) print(6/2) print(5/3) print(-5/3) # # // is division for integers # // is wierd. It goes to the next integer to the left. print(4//2) print(5//3) print(-5//3) print(float(4/2)) # int / and // can produce different values! print(-11/7) #This is a float print(int(-11/7)) #This is a float typecast to an int print(-11//7) #This is an int # # % is a modulus (remainder). Behaves in the style of clock arithmetic. print(5%4) #putting 5 into a modulus of 4 produces 1 print("5%2=", 5%2) # % never use a modulus that is not an integer unless you figure out how it works. # % produces a number between 0 and the modulus #Exponentiation # print(5^2) does not produces exponentiation. Use ** print("5^2=",5**2) print("squareroot(2)=", 2**0.5) # #Can use variables in calculations pizzas=5 hours=2 print("pizzas/hour=", pizzas/hours) # In[46]: #Given a price calculate the sales price with a 10% tax for any price. #listed_price=float(input("What is the original price of the object? ")) #taxpercent=float(input("What is the percent tax on the object? ")) #print("The total price is $", listed_price+(listed_price*(taxpercent/100))) #print("The tax is $", listed_price*(taxpercent/100)) # In[48]: #Order of operations print(2+4/2) #Left to right PEMDAS convention works for addition/subtraction and multiplaction/division. print(2**2*2) print((3**3)**3) print(3**(3**3)) print(3**3**3) #It does not work for exponentiation, which reads from right to left.