''' Purpose: demonstrate arithmetic and use of variables for naming things ''' # name some values a = 13 b = 5 # We are using names (variables) and assigning them values. # So variable a (on the left) is assigned the value 13 (on the right). # We are associating a with 13 and b with 5. # The assignment statement is where the name of the variable is on the left # and its value is on the right. print( "a =", a ) print( "b =", b ) # 88 = c # error! It doesn't know what 88 is. input() # input() is another built in function in Python where it waits for the user # to type something (give it input). An empty input() is just waiting for an input. # You have to type it in the console (the botton part where you see the output). # display some integer calculations # If you can't see the second part with the integer math, hit enter in the console since # there was an input() waiting for you to type something for the next part to print (execute). print( 'Integer arithmetic' ) total = a + b difference = a - b product = a * b dec_quotient = a / b # decimal division int_quotient = a // b # integer division (result will be an int) remainder = a % b # remainder (modulus) operator so the remainder produced by 13/5 power = a ** b # exponentiation a to the b so its 13 ^ 5 # A valid name is an identifier. It needs to start with an alphabetic letter/character # and then you can have # numbers follow it. Soo name your variables a, a1, a23, so on but not like 2, 88. # We will be using these numeric operators in this class for calculations! # Python's basic types: strings, ints, floats (decimals), logical operators (True/False) # There are an infinite number of decimals but we can't represent EVERY decimal number # in Python. (I would remember this; it was on previous tests :)) # Python can only represent up to a certain number of bits in Python when it comes # to floats. The digits in the float values can only reach a certain number of bits. # You can have at most like 15 places of decimal accuracy. # A variable is an identifier! print() is a function NOT an identifier! # Functions are named with identifiers buttt print() itself is a function. print( 'a + b =', total ) print( 'a - b =', difference ) print( 'a * b =', product ) print( 'a / b =', dec_quotient ) print( 'a // b =', int_quotient ) print( 'a % b =', remainder ) print( 'a ** b =', power ) input() # introduce some other built-in functions print( 'Some handy functions' ) c = -10 d = 1.75 e = -1.75 print( "c =", c ) print( "d =", d ) print( "e =", e ) input() abs_c = abs( c ) float_c = float( c ) int_d = int( d ) print( 'abs( c ) =', abs_c ) print( 'float( c ) =', float_c ) print( 'int( d ) =', int_d ) print()