''' Purpose: demonstrate arithmetic and use of variables for naming things ''' # there are so many numbers..... # so python has some guidelines for arithmetic and number representation # the different types of numbers have a concrete number of bits for representation # so your numbers can only be so big # basically, integers that computer does well but decimals it struggles # decimals are represented by floats # name some values # these are ints! a = 4 b = 10 c = -5 d = 100 # a, b, c, and d represent the numbers they are set equal to # They are called variables. (Remember algebra?) # This idea of abstraction is really important in computer science print( a ) print( b ) print( c ) print( d ) # This input is causing the program to pause. It will not continue the later prints until you hit enter. input() print( "a =", a ) print( "b =", b ) print( "c =", c ) print( "d =", d ) input() # these are floats! w = -3.14 x = 4.25 y = 10.75 z = 2.50 print( "w =", w ) print( "x =", x ) print( "y =", y ) print( "z =", z ) input() # display some calculations with integers print( 'Integer manipulation' ) print() # If you put something in quotes, it becomes a string. The words or letters without quotes are variables. print( a, '+', b, '=', 'a' + 'b' ) # string addition: will print out 'ab' as it is adding the string 'a' and the string 'b' together print( a, '+', b, '=', a + b ) # addition print( b, '-', a, '=', b - a ) # subtraction print( a, '*', b, '=', a * b ) # multiplication print( b, '/', a, '=', b / a ) # decimal division input() print( b, '//', a, '=', b // a ) # integer division: ignore/ drop the remainder input() print( b, '**', d, '=', b ** d ) # putting a number to a power input() # super duper important print( b, '%', a, '=', b % a ) # gives the remainder of a division; AKA modulus input() print( -b, '=', -b ) input() #commas separate values; without them there is a syntax error print( 'abs(', c, ') =', abs( c ) ) # absolute value print( 'int(', y, ') =', int( y ) ) # converts y into an integer; in this case drops everything after the decimal print() # display some calculations with floats print( 'Float manipulation' ) print() print( x, '+', y, '=', x + y ) print( y, '-', x, '=', y - x ) print( x, '*', y, '=', x * y ) print( y, '/', x, '=', y / x ) input() print( y, '//', x, '=', y // x )#weird print( y, '%', x, '=', y % x ) print( x, '**', z, '=', x ** z ) input() print( -y, '=', -y ) input() print( 'abs(', w, ') =', abs( w ) ) print( 'float(', x, ') =', float( x ) ) input() # display some calculations with mixed operands print( 'Mixed numeric manipulation' ) #decimals win # the only way to get an integer is to use to ints or integer operators print() #print( a, '+', y, '=', ( a, +, y ) ) we don't want to separate values with commas if they are part of some arithmetic # this will cause an error print( a, '+', y, '=', ( a + y ) ) print( y, '-', b, '=', y - b ) print( a, '*', y, '=', a * y ) print( y, '/', b, '=', y / b ) input() print( y, '//', b, '=', y // b ) print( y, '%', b, '=', y % b ) print( a, '**', z, '=', a ** z )