''' Purpose: demonstrate arithmetic and use of variables for naming things Something to remember: Python represents an integer as an int ''' # computers can only store/represent a certain amount of numbers; cannot represent # every number possible # basic unit of measure of representation in computers is a bit, # hence intsy_bitsy # int = type of number = integers (-3, -2, -1, 0, 1, 2, 3, ...) # float = decimal numbers # use 64 bits for ints and floats --> finite amount of numbers that computers can represent # we can create libraries, containing different functions for us to use in other programs # get a hold of the pause library (module) import pause # the pause library has a function to pause the running of our program # to access a library, we say import --> then we can access the functions inside the library # import is a key word! --> the structure: import name_of_library # CANNOT use import/any key word as an identifier # name some values a = 33 # integer b = 23 # integer c = -256 # negative integer d = 6.9 # decimal # ... means placeholder until you replace it with something; # == is the mathematical equal sign - we'll get here later (don't worry about it right now) # = is the ASSIGNMENT operator, it is NOT mathematical equal sign # a = 49, we are assigning the int 49 to the identifier a # numbers do NOT need quotes; this is IMPORTANT # now every time after this that you are using a, a will represent the integer 49 # so on with b, c, d # identifiers also do NOT need quotes print() print( 'Values of interest' ) print() # formatting the print statements print( 'a =', a ) # we have the string 'a =' exactly, then also print the VALUE of a (which is 49) - # using identifiers do not need quotes print( 'b =', b ) # same with the rest print( 'c =', c ) print( 'd =', d ) print() pause.until_ready() # this will pause your program # the function until_ready() is a function within the pause library that we imported # note the snake_case style for the name of the function until_ready() # the program will pause until the user hits the enter key in the console # once you've hit enter, it will run the program unless you encounter another pausing point # don't use this in your homework print() # perform and display some integer calculations # operators are like +, -, *, /, //, %, ** # operands are things around the operators total = a + b # a = 33, b = 23 (from earlier) --> a + b == 33 + 23 == 56 difference = a - b # a = 33, b = 23 --> a - b == 33 - 23 = 10 product = a * b # multiplication dec_quotient = a / b # decimal division --> includes the decimal places up to 15 decimal places int_quotient = a // b # integer division --> does division, then removes the decimal places; does NOT round remainder = a % b # remainder operator --> gives you the remainder of the division; NOT the quotient power = a ** b # exponentiation, NOT ^ a ** b # gives you back a value, but cannot use it later without assigning the value to an identifier # since the above identifiers are numbers, you can do further arithmetic, or use them in print statements # like below total_divides_difference = total / difference # 56 / 10 --> 5.6 print( 'Calculations' ) print() print( 'a + b =', total ) # we've determined what total is on line 64; total is an identifier 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 ) print() pause.until_ready() print() # introduce some other built-in functions abs_c = abs( c ) # abs(c) gives you the absolute value of c (whatever c is) float_c = float( c ) # float(c) gives you the decimal version of c (whatever c is) int_d = int( d ) # int( d ) gives you the integer version of d print( 'abs( c ) =', abs_c ) print( 'float( c ) =', float_c ) print( 'int( d ) =', int_d )